BLOG

Creating a mock server with Postman

Creating a mock server with Postman

Agustina Hernández

Frontend Engineer

Aug 2, 2022

3 min read

Frontend

Testing

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.

What is a mock server?

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 — .

Why is a mock server necessary?

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!

“The API-First World”, Postman graphic novel
“The API-First World” - Postman graphic novel, p. 27

How does it work?

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!

  1. Click on “Create new Mock Server”.

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.

Conclusion

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.

Agustina Hernández

Frontend Engineer

Aug 2, 2022

3 min read

Frontend

Testing

BLOG

Unlock forbidden knowledge

Explore more

Arrow Icon
Efficiently Caching Translations in React with Zustand and Google Translate API

Frontend

Guides

Efficiently Caching Translations in React with Zustand and Google Translate API

Learn to integrate Zustand and Google Translate API for a seamless translation feature. Cache results to reduce API calls, boost performance, and enhance scalability.

Mauro Davoli

Fast API Development with Hono and Cloudflare Workers

Backend

Technology

Guides

Fast API Development with Hono and Cloudflare Workers

Pablo shares his journey of finding tools to build REST APIs quickly and efficiently. He highlights his experience with Hono, a lightweight framework reminiscent of Express, designed specifically for Cloudflare Workers.

Pablo Haller

A step-by-step infographic showing the process to set up authentication with Next.js using the next-auth library.

Guides

Technology

Basic GitHub OAuth Authentication with Next.js and next-auth

This blog explains how to set up GitHub OAuth in Next.js using next-auth. It covers creating a GitHub OAuth app, configuring environment variables, integrating authentication with a custom route, protecting routes, and managing sessions.

Pablo Haller