Mock REST APIs: configured routes with static or templated responses
Create a temporary mock REST API on socket.help with up to 20 routes, path parameters, response templates, conditions, delays, rate limits and streaming.
Updated 27 October 2026What a mock API does
A mock API is a temporary HTTP endpoint that returns responses you configure. Use it to develop a client before the real API exists, to reproduce an error status or a slow response, or to give a test suite a stable fake dependency. Responses are static text or simple templates; no user code runs.
Create a mock API
POST /api/mocks with a JSON body containing a name and routes. Settings such as visibility and ttlSeconds go in the query string. The response includes endpointUrl and a managementToken, plus an accessToken when the mock is private.
curl -X POST 'https://socket.help/api/mocks?visibility=public' \
-H 'Content-Type: application/json' \
-d '{
"name": "Users",
"routes": [
{ "method": "GET", "path": "/users/:id", "status": 200,
"body": "{\"id\":\"{{path.id}}\"}", "template": true },
{ "method": "POST", "path": "/users", "status": 503,
"body": "{\"error\":\"unavailable\"}", "delayMs": 1500 }
]
}'
# 201 Created
{
"id": "MOCK_ID",
"managementToken": "MANAGEMENT_TOKEN",
"expiresAt": "2026-10-27T13:00:00.000Z",
"visibility": "public",
"accessVersion": "ACCESS_VERSION",
"endpointUrl": "https://socket.help/mock/MOCK_ID"
}
curl https://socket.help/mock/MOCK_ID/users/42
# {"id":"42"}Route fields
A configuration has a name of up to 80 characters and 1 to 20 routes. The whole configuration must fit in 80 KiB.
| Field | Required | Rules |
|---|---|---|
| method | Yes | GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD or ANY |
| path | Yes | Starts with /, up to 200 characters; :name segments match any value |
| status | Yes | Integer from 200 to 599 |
| body | Yes | String up to 50 KiB |
| headers | No | Up to 10; only Content-Type and X-Mock-* names, values up to 200 printable ASCII characters |
| delayMs | No | 0 to 2000 milliseconds, default 0 |
| template | No | true to insert request values into a JSON or plain text body |
| condition | No | {source, key, value}: source is header, query or body; value up to 512 characters |
| requestsPerMinute | No | 1 to 120; extra requests get 429 with Retry-After |
| stream | No | {mode, intervalMs}: mode sse or text, interval 10 to 1000 ms |
How requests are matched
Call routes under endpointUrl, for example https://socket.help/mock/MOCK_ID/users/42. A route matches when the method is equal, the path has the same number of segments with equal literal segments, and the condition (if any) holds. Trailing slashes are ignored.
The first route in configuration order wins. If no route has the request method, HEAD falls back to a GET route, then any method falls back to an ANY route. No match returns 404 with {"error":"No matching mock route."}.
A condition compares one request header, query parameter or top-level JSON body field to an exact string. Use conditions to return different responses from the same path, for example a 401 route and a 200 route for the same path selected by an Authorization value.
Response content
Content-Type defaults to application/json. Allowed types are application/json, application/problem+json, application/xml, text/plain, text/csv and text/event-stream, optionally with ; charset=utf-8. Responses with status 204, 205 or 304 and HEAD requests send no body.
Templates replace {{path.name}}, {{query.name}} and {{body.name}} with the request value. In JSON templates, placeholders must sit inside strings and values are JSON-escaped. Missing values become empty strings. Each inserted value is limited to 4,096 characters and the rendered body to 64 KiB. Templates do not support XML or streaming.
Streaming routes must use GET or ANY with status 200. Each line of the body is sent as one chunk, or as one server-sent event with sequential id and event: message, at the configured interval. A stream allows up to 20 lines of 4 KiB and five seconds of delivery.
Read, update and delete
GET /api/mocks/{id} returns the configuration, visibility, accessVersion, expiresAt, uses (the number of requests received) and endpointUrl. PUT /api/mocks/{id} replaces the whole configuration with a new valid body and returns 204. DELETE /api/mocks/{id} removes it immediately.
curl -X PUT https://socket.help/api/mocks/MOCK_ID \
-H "Authorization: Bearer $MANAGEMENT_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"name":"Users","routes":[{"method":"ANY","path":"/health","status":200,"body":"ok","headers":{"content-type":"text/plain"}}]}'
# 204 No ContentLimits
Each mock API accepts up to 120 requests per minute in total; per-route requestsPerMinute applies on top. When stream capacity is reached, new streams get 503 with Retry-After: 5.
Frequently asked questions
Can a mock API run custom code or call another service?
No. Responses are static text or templates that insert path, query and top-level JSON body values. There are no expressions, scripts or outbound requests.
How do I return different responses from the same path?
Add routes with the same method and path but different conditions, for example on a header, query parameter or body field. The first matching route in configuration order is used, so place the unconditional route last.
Which response headers can I set?
Only Content-Type and headers that start with X-Mock-, up to 10 per route. Other headers are rejected when you create or update the mock.
Can I test retry and backoff behaviour?
Yes. Set requestsPerMinute on a route. Requests beyond the quota get 429 with a Retry-After header, and the window starts with the first counted request.