Mock Server - Hook

Hook Docs / Mock Server

Mock Server

Purpose

The mock server lets you test Hook requests against a local HTTP endpoint without depending on an external API. Define routes with fixed responses and run the server on localhost.

Routes JSON format

The mock server reads routes from a JSON file. Each route maps an HTTP method and path to a fixed response.

[
  {
    "method": "GET",
    "path": "/api/users",
    "status_code": 200,
    "content_type": "application/json",
    "body": "[{\"id\":1,\"name\":\"Alice\"}]",
    "delay_ms": 0
  },
  {
    "method": "POST",
    "path": "/api/users",
    "status_code": 201,
    "content_type": "application/json",
    "body": "{\"id\":2,\"name\":\"Bob\"}",
    "delay_ms": 100
  },
  {
    "method": "GET",
    "path": "/health",
    "status_code": 200,
    "content_type": "text/plain",
    "body": "ok",
    "delay_ms": 0
  }
]

Route fields

Route matching

Routes are matched by method and path. The first matching route wins. If no route matches, the server returns 404 with an empty body.

Path matching is exact. There is no wildcard or regex support.

Starting from the GUI

  1. Open the Mock Server panel.
  2. Click Load Routes and select a routes JSON file (or click New for a starter template, or paste JSON directly).
  3. Set the port (default: 18080).
  4. Click Start.

The server runs in a background thread. The status label below the buttons shows the current state:

The error message persists until the next successful Start or a Stop click.

To stop the server, click Stop.

Starting from the CLI

hook mock routes.json [--port N]

Arguments:

The server runs in the foreground. Press Ctrl+C to stop it.

Example:

hook mock test-routes.json --port 9090

Testing against the mock server

Once the server is running, point your requests at it.

  1. Set the URL to http://localhost:18080/api/users (or whatever port you chose).
  2. Send the request.
  3. The mock server responds with the fixed response defined in the routes file.

With environments, set a variable:

{
  "name": "local",
  "variables": {
    "base_url": "http://localhost:18080"
  }
}

Then use {{base_url}}/api/users in your request URL.

Simulating latency

Set delay_ms on a route to simulate a slow server. The mock server waits the specified number of milliseconds before sending the response. This is useful for testing timeout behavior.

Example: a route with "delay_ms": 5000 waits 5 seconds before responding. A request with a 3000ms timeout will time out.

Limitations