Postman mock servers can do much for us, but what do they do? Let’s first look at what they are and how to build them to understand them better.
A mock server is a simulated server that we can create to represent a real one. They simulate an API by returning predefined data, allowing you to test it before it’s ready for production — or without using production data — .
We can simulate the behavior of a real API and make requests that return mock data defined within Postman. This is useful if you don’t have a production API ready or don’t want to run your requests against real data yet!
When you send a request to a mock server, Postman will match the request configuration to the examples you have saved and respond with the data you added to the example.
So, are you ready to create a mock server for your project? Follow these steps!
2. If you have already created an endpoint collection, click “Select an existing collection”; otherwise, create a new one.
3. Give your mock server a name and select an environment if you have one.
4. Copy the Mock URL.
5. You can now start saving examples to be used as your mocked data. You can hit a real API, get the response and save it, or create a fake sample response.
6. Replace the base part of the URL in your services with the URL of the mock server (everything before the path, for example, up to /login) and start using it.
In conclusion, I would say the mock server is the best option if the API is not ready and the front-end needs to start working. You can use your mock URL in your local project; this way, the front-end will work as if it were the real API without generating a lot of unnecessary test data. You can create an entire mock service with a single request. In this case, you can deploy and test clients much faster since you don’t have to make a complex working solution. You can write tests before the service is built and create different scenarios.
Our co-workers can work in parallel without waiting for the services to be created in the real API.
You can read more about mock servers here.