← Back to Chapters

Mock Servers in Postman

? Mock Servers in Postman

? Quick Overview

Mock Servers in Postman allow developers to simulate APIs without a real backend. They return predefined responses, helping frontend and mobile teams continue development even when actual APIs are not ready.

? Key Concepts

  • Mock servers respond with static or example-based data
  • Mocks are based on collections and saved examples
  • Useful for parallel development and testing
  • Supports request matching by method, URL, headers, and body

? Syntax / Theory

A mock server is created from an existing collection. Each request in the collection must have one or more saved examples that define how the mock server responds.

Mock URL Examples Request Matching

? Code Example(s)

? View Code Example
// Example JSON response used by Postman Mock Server
{
  "status": "success",
  "message": "User fetched successfully",
  "data": {
    "id": 101,
    "name": "Rahul",
    "email": "rahul@example.com"
  }
}

? Live Output / Explanation

Mock Response

When the mock URL is called, Postman returns the above JSON response with the defined HTTP status code, headers, and body.

? Interactive Example

Click the "Send" button below to simulate calling a Postman Mock Server. It will retrieve the saved example data immediately.

GET
Status: 200 OK Time: 124ms
 
 

Or use actual JavaScript code:

? View Code Example
// Fetching data from a Postman Mock Server
fetch("https://mock.postman.com/users")
.then(res => res.json())
.then(data => console.log(data));

? Use Cases

  • Frontend development without backend dependency
  • API contract validation
  • Training and demos
  • Testing error scenarios

? Tips & Best Practices

  • Always save multiple examples for different responses
  • Use clear example names (200 OK, 404 Not Found)
  • Enable request matching for realistic behavior
  • Keep mock data close to real API structure

? Try It Yourself

  1. Create a new Postman collection
  2. Add a request and save an example response
  3. Create a mock server from the collection
  4. Call the mock URL in browser or Postman