Useful tools: Postman Mock Servers
Postman has been around for years, but many of my colleagues, including myself, have used it mainly for managing API collections and manual API testing. Postman means so much more.
What is a Mock Server?
A mock server is used to simulate an API. We can call it a simulated API. It will have its own URL and it will return mocked predefined data. Usually these kind of servers are used to test APIs before they are available or live.
Postman Mock Servers use cases
- You would like to write tests for your API before it is ready or live.
- You work on a service that needs to do API requests to a third party dependency. That dependency is not yet accessible for you to use, but it has a good documentation mentioning how the request and response should look like, including request paths, query params, headers, request body if any, response body if any and so on.
- You would like to simulate different responses and HTTP statuses for an API dependency that are difficult to simulate otherwise.
- You would like to simulate response network delays for an API.
Steps for creating a mock server
- Open Postman, go to
Mock Serversand press the
Create Mock Serverbutton
- Choose the
- Press the
- Type a
Mock server nameand choose if you would like to simulate a fixed network delay
- Press the
Create Mock Serverbuton
After you press the
Create Mock Server button a few things will be created:
- You will have a URL having this format: https://POSTMAN_UUID.mock.pstmn.io that will be also added in a Postman Environment with the same name as your mock server.
- You will have a Collection created with the same name as your mock server that you can use to test your newly created mock server.
Now simply use the mock server URL for your specific use case.
The above example was a very simple one. Once you have the Collection in place you can add additional paths, additional query params, request headers, response headers and so on. The above example is only a place to start in the world of Postman Mock Servers.
Have fun with Postman!