← All docs
Guides

Configuring Mock Responses

Control status codes, response bodies, headers, and latency for each mock endpoint.

Overview

Every endpoint in your schema has a mock config — the exact response Mockra will return when that endpoint is called. You can edit any mock config from the dashboard by clicking the pencil icon next to an endpoint.

Changes take effect immediately. No redeployment, no cache purge needed.


Status code

Set the HTTP status code the endpoint should return. Any valid HTTP status code is accepted.

Common use cases:

Scenario Status code
Happy path 200 OK
Resource created 201 Created
Resource not found 404 Not Found
Server error 500 Internal Server Error
Rate limited 429 Too Many Requests
Unauthorized 401 Unauthorized

Response body

The response body can be any valid JSON value or a plain string.

JSON object:

{
  "id": 42,
  "name": "Alice",
  "email": "alice@example.com",
  "active": true
}

JSON array:

[
  { "id": 1, "name": "Alice" },
  { "id": 2, "name": "Bob" }
]

Plain string (set Content-Type: text/plain in headers):

OK

Empty body — leave the field blank to return a response with no body. Useful for 204 No Content responses.


Response headers

Add custom HTTP headers to any mock response. Common uses:

Header Example value
Content-Type application/json
X-Request-Id abc-123
Cache-Control no-store
Access-Control-Allow-Origin *
X-Rate-Limit-Remaining 42

Headers are added to every response from that endpoint. Mockra always sets Content-Type: application/json by default — override it here if needed.

Pro/Enterprise: Use variable interpolation in header values to mirror request data. For example: X-Echo-User: {header.x-user-id}.


Latency simulation

Pro and Enterprise only.

Add an artificial delay to simulate a slow or degraded upstream API. Set a value in milliseconds (0–5000).

latency_ms: 350

With 350ms configured, every response from this endpoint will be delayed by 350ms before being returned. The delay is applied before sending the response body.

Use cases:

  • Test timeout handling in your client code
  • Simulate database query latency
  • Reproduce intermittent slowness for performance profiling

Applying changes

After editing a mock config and saving:

  1. The new config is written to the database
  2. The edge cache is updated immediately
  3. The next request to that endpoint returns the new response

There is no propagation delay — the cache update is synchronous with the save operation.


Testing your config

After saving, verify the response with curl:

curl -i https://mock.mockra.io/{namespace}/{path}

The -i flag shows response headers so you can verify your custom headers and status code.


Resetting to defaults

If you want to restore the auto-generated default response from your OpenAPI spec, delete the custom body and headers and save. Mockra will re-derive the default from the spec's example or schema definition.

To completely reset all endpoints in a workspace to their defaults, re-upload the schema. This recreates all mock configs from scratch.


Stateful responses

If you need an endpoint to return different responses on successive calls — for example, pending on first call and complete on second — see Stateful Mocks.

Try Mockra free

5,000 requests/month, no credit card required. Upload an OpenAPI spec and get mock endpoints in under 60 seconds.

Start for free