0
0
Postmantesting~5 mins

Creating mock servers in Postman

Choose your learning style9 modes available
Introduction

Mock servers let you pretend your API is ready even if it is not. This helps you test and develop without waiting.

You want to test your app before the real API is finished.
You need to share API responses with your team early.
You want to simulate different API responses to check error handling.
You want to develop frontend and backend separately.
You want to demo your API without exposing the real server.
Syntax
Postman
1. Open Postman.
2. Click on 'New' > 'Mock Server'.
3. Choose to create from an existing collection or create a new one.
4. Define example requests and responses.
5. Start the mock server and get the mock URL.
6. Use the mock URL in your tests or app.

You create mock servers based on collections with example responses.

Mock servers provide a URL that returns the example responses you set.

Examples
This sets up a mock server that returns a list of users when you call GET /users.
Postman
Create a mock server from a collection with GET /users example response.
This helps test how your app reacts to different login results.
Postman
Create a mock server with multiple example responses for POST /login to simulate success and failure.
Sample Program

This example shows how to create a mock server that returns a fixed list of users. You can use this URL in your app or tests to get predictable data.

Postman
1. In Postman, create a collection named 'User API'.
2. Add a GET request to /users.
3. Add an example response with status 200 and body [{"id":1,"name":"Alice"}].
4. Click 'New' > 'Mock Server'.
5. Select 'User API' collection.
6. Name the mock server 'User API Mock'.
7. Create the mock server.
8. Use the mock URL to send GET /users request.
9. You receive the example response with user data.
OutputSuccess
Important Notes

Mock servers only return the example responses you set; they do not run real code.

Use descriptive example names to manage multiple responses easily.

Mock servers help avoid delays caused by backend development or downtime.

Summary

Mock servers simulate API responses for testing and development.

They are created from collections with example requests and responses.

Using mock servers helps teams work faster and catch issues early.