Answer
Postman Mock Server
A Mock Server in Postman simulates API endpoints by returning predefined example responses. This allows frontend developers to work without a real backend, and testers to test without a live API.
Why Use Mock Servers?
- ✓Frontend development can proceed before backend APIs are ready
- ✓Test edge cases (slow responses, errors) without changing real API
- ✓Reduce dependency on backend teams
- ✓Test 3rd party API integrations without actually calling them
Creating a Mock Server
Method 1: From a Collection
- ✓Select your Collection
- ✓Click ... → Mock Collection
- ✓Give it a name (e.g., "User API Mock")
- ✓Choose environment (optional)
- ✓Click Create Mock Server
- ✓Postman generates a URL like:
https://abc123.mock.pstmn.io
Method 2: From Scratch
- ✓Click Mock Servers in the sidebar
- ✓Click + → Create Mock Server
- ✓Add API paths and HTTP methods
- ✓Define example responses
Adding Examples to Requests
- ✓Open a saved request (e.g.,
GET /users) - ✓Send the real request to get a response
- ✓Click Save Response → Save as example
- ✓The example is now returned by the mock server
Example Response Definition
For GET /api/users:
JSON
{
"data": [
{ "id": 1, "name": "John", "email": "john@test.com" },
{ "id": 2, "name": "Jane", "email": "jane@test.com" }
],
"total": 2
}
Using the Mock Server
Update your environment variable:
CODE
base_url = https://abc123.mock.pstmn.io
Send requests as normal — Postman returns mock responses.
Dynamic Mock Responses
Postman matches mock responses based on:
- ✓URL path
- ✓HTTP method
- ✓Query parameters
- ✓Request headers
Create multiple examples with different query params to return different mock data.
