Skip to content

.mock files

.mock files define a local HTTP mock server. Each file boots an independent server on a configurable port, serving routes you declare with match rules and templated responses. Sendpad reloads the server on every save.

@port = 3500
@base-path = /v1
@cors = permissive
### GET /users/:id
# @match path = /users/:id
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": {{param.id}},
"name": "Jane",
"createdAt": "{{now}}"
}
### POST /users
# @match method = POST
# @status 201
# @delay 120ms
Content-Type: application/json
{ "id": "{{uuid}}", "name": "{{body.name}}" }
### Catch-all
# @match path = *
HTTP/1.1 404 Not Found
{ "error": "Not found" }

Press ⌘Enter or click ▶ at the top of the file to start the server.

DirectiveDescription
@port <n>Port to bind (required)
@base-path <path>Prefix applied to every route
@cors <mode>permissive, echo, or off (default off)
@delay-default <ms>Default delay for every matched response
@forward <url>Proxy non-matching requests to an upstream — Pro

Each ### line declares a route. Method and path can be written on the ### line:

### POST /users

…or split between ### (a free-text label) and # @match directives:

### Create user
# @match method = POST
# @match path = /users
DirectiveDescription
# @match method = <METHOD>Match HTTP method
# @match path = <pattern>Match URL path — supports :param, *, **
# @match query.<k> = <v>Match a specific query-string value
# @match header.<name> contains <v>Match a header value
# @match body contains <text>Match against the request body
DirectiveDescription
# @status <code>Response status (default 200)
# @header <name>: <value>Response header
# @delay <ms> or # @delay <min>-<max>Fixed or random delay
# @repeat <n>Serve this response only the first N matches
# @template <var>Declare a template variable for use in the body

The body after the blank line is returned verbatim, with template substitution applied.

Inside the body you can reference request data via built-in variables:

VariableSource
{{path.0}}, {{path.1}}, …Positional URL segments
{{param.<name>}}Named path parameter (/users/:id{{param.id}})
{{query.<name>}}Query-string value
{{body.<json-path>}}Value from an incoming JSON body
{{header.<name>}}Incoming request header
{{uuid}}Fresh UUID v4
{{now}}ISO-8601 timestamp
{{random(min,max)}}Random integer

Any variable declared with # @template <var> can be referenced as {{<var>}} and is resolved from .env or file-level variables.

Use @forward to proxy non-matching requests to a real upstream — useful when mocking only part of a surface area:

@port = 3500
@forward = https://api.prod.example.com
### Stubbed endpoint
# @match path = /v1/features/beta
HTTP/1.1 200 OK
{ "feature": "enabled" }

Any request that doesn’t match a route is transparently proxied. Requests are logged in the mock log with a forwarded badge.

Save the file and the running server restarts immediately. In-flight requests complete against the old definition; new requests hit the new one. The Mock panel shows a toast on each reload.