Intro to Mock Servers
- The mock server is a fake server that simulates as a real server to help the users for testing and checking their APIs and APIs responses.
- During the various API testing, a Mock server is used when specific responses are required to be received that are not readily available on the web servers or for certain testing, which cannot be done due to security issues on real servers.
How Mock Server Works
When you send the request then MockServer receives that request, it matches the request against the specified requirement, and if no matches are found, it will proxy the request, if possible. The request would otherwise return a 404.
For each Received Request:
- Find matching expectations and perform an action.
- If the request does not match the expectation, then it will proxy request.
- if not a proxy request will return 404
Here the expectation is the action being taken, which could be returned to a response.
Types of Mock Servers
We can create two types of Mock Servers in Postman:
1. Private mock server
These cannot be accessed by everyone. When you create a private mock server, users may share the collections with their teammates lying under it. Your team may use the mock by adding API keys in the request header x-api-key, like x-api-key:<your postman API key>.
2. Public mock server
Public mock servers are open to all. When you share this mock server, users are not required to add a Postman API key to consume the mock.
Benefits of Postman Mock server
- To check your own API during development and before you make that API live on your organization’s server.
- To get faster reviews and bugs.
- Without any authentication, any type of request can be made into the server.
- To test the dependencies inside the API until they are open to everyone.
- For QA engineers, use this to check or isolate external dependencies and check the integration.
- Using it before actual endpoints are available by front end developers.
- A mock server is used by engineers to create a prototype of their idea to submit it for funding to the investors.