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

Building cool search UIs with Algolia and InstantSearch

Frontend

Technology

Guides

Building cool search UIs with Algolia and InstantSearch

In this article, we’re going to pick some characters from a video game (Genshin Impact) and display them in a fancy way using the aforementioned programs.

Pablo Haller

Tropical.rb 2024 Recap

Conference

Backend

Tropical.rb 2024 Recap: My Experience

It’s been two months since (time flies!) but I couldn’t resist sharing my first-time experience at Tropical.rb, the largest Ruby on Rails event in Latin America.

Franco Pariani

Franco Pariania and Nicolas Erlichman. Gogrow

Business

Welcoming a New Era: Introducing Our New Co-CEO at GoGrow

We’re thrilled to share a significant update to GoGrow’s leadership. Nicolas Erlichman is joining Franco Pariani as co-CEO.

GoGrow