Introduction

When creating mock APIs, it's crucial to simulate real-world HTTP responses accurately. MockX provides powerful features for configuring response headers and status codes, allowing you to create realistic API simulations. In this guide, we'll explore how to use these features effectively.

Understanding HTTP Status Codes

HTTP status codes are essential for communicating the result of an API request. MockX supports all standard HTTP status codes, allowing you to simulate various scenarios:

  • 2xx Success codes (200, 201, 204)
  • 3xx Redirection codes (301, 302, 304)
  • 4xx Client error codes (400, 401, 403, 404, 429)
  • 5xx Server error codes (500, 502, 503)

Configuring Response Headers

Response headers provide additional information about the response. Here's how to set up common headers in MockX:

{
    "headers": {
        "Content-Type": "application/json",
        "Cache-Control": "no-cache",
        "Access-Control-Allow-Origin": "*",
        "X-Rate-Limit-Limit": "100",
        "X-Rate-Limit-Remaining": "99"
    }
}

Common Use Cases

1. CORS Configuration

For frontend development, you might need to configure CORS headers:

{
    "headers": {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE",
        "Access-Control-Allow-Headers": "Content-Type, Authorization"
    }
}

2. Rate Limiting Simulation

Simulate rate limiting scenarios with appropriate headers:

{
    "status": 429,
    "headers": {
        "X-Rate-Limit-Limit": "100",
        "X-Rate-Limit-Remaining": "0",
        "X-Rate-Limit-Reset": "1620000000",
        "Retry-After": "60"
    }
}

3. Cache Control

Configure caching behavior for your responses:

{
    "headers": {
        "Cache-Control": "max-age=3600",
        "ETag": "\"33a64df551425fcc55e4d42a148795d9f25f89d4\"",
        "Last-Modified": "Wed, 21 Oct 2025 07:28:00 GMT"
    }
}

Best Practices

  • Always include appropriate Content-Type headers
  • Use realistic status codes that match your API's behavior
  • Include relevant headers for your specific use case
  • Test different status code scenarios
  • Document your header configurations

Conclusion

By mastering response headers and status codes in MockX, you can create more realistic and effective API simulations. This will help you test your applications more thoroughly and ensure they handle various HTTP scenarios correctly.

Ready to Master API Response Headers?

Start using MockX today to create realistic API responses with custom headers and status codes.

Create Your First Mock API