Archived topic — some details may be out of date.
Mock servers built from saved collection examples are still supported. Postman now also has code-based mocks: JavaScript request handlers plus aconfig.yaml, stored as files in your Git repository, which you can run locally or deploy. Create one in the app, or use the Postman CLI to generate one from an OpenAPI spec, collection or dataset (postman mock generate) and run it (postman mock run). See About mocks and Create a mock.
Working with an AI coding agent? The Postman plugin can build and run mocks for you.
For current help, see the Postman docs, try the free Postman tools (no account needed), or join us on Discord.
I have created a collection featuring three requests based on the following method and URL:
GET 200 OK
{{url}}{{path}}/subject/{{subject_nr}}/honden
Headers
| Accept | application/json |
|---|---|
| x-api-key | {{apiKey}} |
| x-mock-response-code | 200 |
I have then created a mock server for the collection featuring the following mocked request/response:
Example Request : GET 200 OK
curl --request GET \
--url 'http://{{url}}{{path}}/subject/{{subject_nr}}/honden' \
--header 'Accept: application/json'
Example Response : 200 OK
{
"datum_ingang": "2/5/18",
"totaal_aantal_honden": 1
}
NOTE: The mock server shares the same environment the collection uses, all the abovementioned environment variables are substituted correctly at runtime.
When the request is sent to the mock server, the following output is shown in the console:
GET
https://1f586124-667b-4d20-b3cc-ce66c99d0cba.mock.pstmn.io/urds/wrd/api/hond/v1/subject/0303200001/honden
* * Request Headers:
* accept:"application/json"
* accept-encoding:"gzip, deflate"
* cache-control:"no-cache"
* host:"1f586124-667b-4d20-b3cc-ce66c99d0cba.mock.pstmn.io"
* postman-token:"4e5fff38-af47-4994-89e5-1e1e9ca75668"
* user-agent:"PostmanRuntime/7.3.0"
* x-api-key:"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
* x-mock-response-code:"200"
* * Response Headers:
* access-control-allow-credentials:""
* access-control-allow-headers:""
* access-control-allow-methods:""
* access-control-allow-origin:"*"
* access-control-expose-headers:""
* connection:"keep-alive"
* content-encoding:"gzip"
* content-length:"185"
* content-type:"application/json; charset=utf-8"
* date:"Thu, 25 Oct 2018 10:08:25 GMT"
* etag:"W/"d5-wZgN2LuPyvxuKCxlKWOeZw""
* server:"nginx"
* vary:"Accept-Encoding"
* x-ratelimit-limit:"60"
* x-ratelimit-remaining:"59"
* x-ratelimit-reset:"1540462165"
* * Response Body:
* error:
* name:"mockRequestNotFoundError"
* message:"We were unable to find any matching requests for this method type and the mock path, '/urds/wrd/api/hond/v1/subject/0303200001/honden', in your collection."
404
218 ms
My questions are:
- Why is this happening?
- Are TEMPLATE parameters in the path supported by the mock server?