Skip to main content
The mock server is an experimental feature. The syntax and behavior may change in future releases.
hitspec can start a mock HTTP server that serves responses based on your .http test files. This is useful for frontend development, integration testing, and working offline without a live backend.

Basic Usage

The mock server reads your test files and creates endpoints that return responses matching the expected assertions.

How It Works

hitspec inspects the requests defined in your .http files and creates one route per request, matched by method and path (path variables like /users/{{id}} become wildcards that match any value). When an incoming request matches a route, the server builds the response from, in order of precedence:
  1. A >>>mock block — if present, its content is returned verbatim as the response body.
  2. Assertions — otherwise the body is inferred from the request’s assertions.
In both cases the status code comes from expect status <code> (default 200) and the Content-Type is application/json.

Custom Mock Responses

Add a >>>mock block to define the exact response body the server should return. This is the most direct way to mock a response — including shapes that assertions can’t express, like arrays:
A GET request to /users/1 returns the >>>mock body verbatim with status 200.
The mock body is returned verbatim{{variable}} placeholders are not interpolated. The block ends at the first line that begins with <<<, so the body can contain >>>/<<< mid-line (for example inside a JSON string).

Inferring the Response from Assertions

If a request has no >>>mock block, the server builds the body from its assertions:
  • expect body.<field> == <value> assertions are assembled into a JSON object of those fields.
  • expect body == <value> returns that value verbatim as the body.
  • With no body assertions, the server returns {"status": "ok"}.
For example:
A GET request to /products/1 matches this route and returns:

Flags

Adding Artificial Delay

Simulate network latency with the --delay flag:
This adds a 100ms delay before every response, which is useful for testing loading states in frontend applications.

Example

Given this test file:
Start the mock server:
Then test against it:
The mock server is especially useful during frontend development. Point your frontend at the mock server and develop against stable, predictable responses without needing a live backend.
Last modified on July 13, 2026