I am trying to form dynamic responses based on request params using postman mock server
Please help me. Any links or direct answers much appreciated
The postman mocks documentation found on this page https://learning.postman.com/docs/designing-and-developing-your-api/mocking-data/mocking-with-examples/ mentions that mock responses only return examples that match the following request criteria:
*URL endpoint
*request method type,
*status code
‘Your examples might vary depending on the URL endpoint, request method type, or status code. If you have multiple examples saved to the same mock, you can choose to save each example under a unique URL endpoint like you saw in this example with /get
and /test
. Alternatively, if you have saved examples with different response status codes, you can send an authenticated request to the mock endpoint along with the x-mock-response-code
header specifying which integer response code your returned response should match.’ - Postman Documentation
I agree that having request parameters and request query string matching would also be very helpful to match against examples to return.
Update: pallab.nag below mentioned that on the page provided, below there is a separate section that mentions query parameters also can be used to return matching examples.
means to differentiate each example, there should be definitely some uniqueness in url or request body or headers?
What do you mean by “dynamic”?
If you just want different responses based on different request parameter values, add those request parameter values to the example. You’ll need multiple examples, one for each variation.
Best,
Kevin
thanks i got some idea
how can i validate request body
like i want to check if the request has few keys irrespective of values?
ex : if(pm.request.body.has(“key1”)
{
//do something
}
is it possible
@darren.capner although
https://learning.postman.com/docs/designing-and-developing-your-api/mocking-data/mocking-with-examples/ here it is defined that different response based on query params is available but its not working .
did you got to test it?
is it feasible?