I'm building an API with WCF (C#) and testing it with Postman. I seem to be having trouble using the "Params" section within Postman, as it is translating any key value pairs I input into Query String Params.
My Contract specifies the UriTemplate like so...
[OperationContract]
[WebGet(UriTemplate = "/GetClientDataFromAlias/Alias/{alias}",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
GetClientDataFromAliasResponse GetClientDataFromAlias(string alias);
Yet when I run the request through Postman the URL is translated into the following...
http://troikawcf.localhost/ClientWCFService.svc/GetClientDataFromAlias?Alias=myalias
What I would like it to translate to is the following, to match my contract
http://troikawcf.localhost/ClientWCFService.svc/GetClientDataFromAlias/Alias/myalias
Am I missing a setting in Postman to set all params in the Path format? Or do I need to change my Contract to utilize Query String Params?
See screen grab below for more info...
Many Thanks
I figured out a way to get this working.
You can use placeholders in the URL bar within Postman that enable you to still utilize the "Params" section to pass through the actual values. This is extremely helpful for quick editing of param values without parsing through the URL. You can just set your URL structure in the Address Bar and let the "Params" Section do the rest.
To do this, you need to add your Path Parameter to the URL as you would do normally, but instead of adding a value, add a placeholder prefixed with a colon. The Placeholder will now appear automatically in the "Params" Section within the 'Key' column. You can add in the actual parameter value in the 'Value' column so that when you run your request the placeholder will get swapped out with the actual value.
Here's an example :- http://troikawcf.localhost/ClientWCFService.svc/GetClientDataFromAlias/Alias/:Alias
An here's an screen capture of Postman to further clarify :-
I hope this helps someone else out in the future as it baffled me for days why a REST client would not have support for Path Params.
I believe you want to Creating cURL commands in Postman.
hope you can find the answer here.
also consider using Fiddler4
in order to test the restful services.
A UriTemplate
has basically two parts (from MSDN):
A path consists of a series of segments delimited by a slash (/). Each segment can have a literal value, a variable value (written within curly braces [{ }], constrained to match the contents of exactly one segment)
The query expression can be omitted entirely. If present, it specifies an unordered series of name/value pairs. ... Unpaired values are not permitted.
So, there are basically two ways to include parameters in the URL for a webrequest:
Thesa are the variables in the curly braces that appears before the query and would be like:
GetClientDataFromAlias/{alias}
These are the name/value pairs that appears in the optional query expression and would be like
GetClientDataFromAlias?Alias=myalias
In your case, when using the Params section in Postman, Postman will add the key/value parameters to the query expression, NOT the path segment because the query expression consists of
an unordered series of name/value pairs.
If you want your parameters to be in the path segment, you need to remove the key/value parameter in Postman and add the parameter in the URL of the request within curly braces
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With