Mock Response

Mock Response

✅ What a “Mock Response” Is

A mock response is a simulated API response you create to imitate what an external system would have returned.

It’s used during development and testing so you don’t need a live system available.

🧱 What a Mock Response Usually Contains

A mock response typically includes:

1. Headers

Metadata about the response.

Examples:

  • Content-Type: application/json

  • Authorization: Bearer ...

  • X-RateLimit-Remaining: 99

  • Set-Cookie: sessionid=abc123

Headers are important because they can:

  • Affect how the app parses the response

  • Provide information about authentication

  • Indicate pagination, rate limits, caching, etc.

Mocking headers helps you test how your integration behaves in these situations.

2. Data (Body / Payload)

The actual content returned by the API.

Examples:

[ { "id": 1, "name": "Alice Johnson", "email": "alice.johnson@example.com", "role": "admin", "active": true } ]

Mocking the data allows you to:

  • See how your integration processes real-world structures

  • Test error conditions

  • Validate UI rendering

  • Work offline or without the actual service

🎯 Why Mocking Headers + Data Matters

1. Develop without the real API

You don’t need the third-party system available. 

2. Test how your integration reacts to different conditions

  • Expired token? → mock 401 Unauthorized

  • Rate limit hit? → mock 429 Too Many Requests

  • Unexpected format? → see if your code crashes

3. Reproduce issues

You can test with the exact same headers and data that caused a bug. 

4. Faster development

No waiting for slow external APIs. 

5. Safer

You avoid sending real data to real endpoints in development environments.

image-20251117-131036.png