Advanced Features12 min read

Response Customization

Configure status codes, response delays, custom headers, and advanced response behaviors

What is Response Customization?

Response customization allows you to control exactly how your mock API responds to requests. This includes HTTP status codes, response delays, custom headers, and conditional responses based on request parameters.

Status Codes

Return any HTTP status code to simulate success, errors, or edge cases

Response Delays

Add artificial delays to test loading states and timeout handling

Custom Headers

Set custom response headers for CORS, caching, and authentication

Customizing HTTP Status Codes

By default, Mock API Builder returns appropriate status codes for each operation (200 for GET, 201 for POST, etc.). You can override these to test error handling in your application.

Common Status Codes
Use these to simulate different scenarios
200

OK - Success

Standard successful response

201

Created

Resource successfully created

204

No Content

Success with no response body (DELETE operations)

400

Bad Request

Invalid request data or parameters

401

Unauthorized

Authentication required or failed

403

Forbidden

Authenticated but not authorized

404

Not Found

Resource doesn't exist

500

Internal Server Error

Server-side error occurred

How to Set Custom Status Codes

  1. 1. Navigate to your project's endpoint editor
  2. 2. Select the endpoint you want to customize
  3. 3. Find the "Response Settings" section
  4. 4. Enter your desired status code (e.g., 404, 500)
  5. 5. Save changes - the endpoint will now return that status code

Adding Response Delays

Response delays help you test how your application handles slow network conditions, loading states, and timeout scenarios.

Use Cases for Delays
  • Test Loading States: Ensure your loading spinners and skeletons work correctly
  • Timeout Testing: Verify your app handles request timeouts gracefully
  • Slow Network Simulation: Test behavior on 3G/4G mobile connections
  • Race Condition Testing: Identify timing-related bugs in your code

Setting Response Delays

Delay Range: 0ms to 10,000ms (10 seconds)

Recommended Values:

  • 500ms-1000ms: Normal API response time
  • 2000ms-3000ms: Slow network conditions
  • 5000ms+: Timeout testing
Example: Testing Loading States

Add a 2-second delay to your user list endpoint to ensure your loading spinner displays:

typescript

Custom Response Headers

Custom headers allow you to control caching, CORS policies, content types, and other HTTP behaviors.

Common Custom Headers

Cache-Control

Control how responses are cached by browsers and CDNs

text

X-RateLimit-*

Simulate rate limiting headers

text

Content-Type

Specify response format (usually set automatically)

text

X-Custom-Header

Add any custom header for testing

text

CORS Headers

Mock API Builder automatically handles CORS for local development, but you can customize these headers if needed:

text

Best Practices

Test Realistic Scenarios

• Use realistic delay times (100-3000ms) instead of extreme values

• Test both success and error status codes

• Verify your app handles all HTTP status codes gracefully

Document Custom Responses

• Add comments in your endpoint descriptions explaining custom settings

• Document which endpoints have delays or custom status codes

• Share this information with your team

Use for Development, Not Production

• Response customization is for testing and development

• Remove artificial delays before moving to production APIs

• Use real production status codes in your final implementation