For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /docs/quick-start/index.md.

Serve your first mock

Make GET /users/123 return Ada. Once you see the response, add a second outcome and switch to it while the server is running.

Install the CLI

For a project install, run the command in the directory containing your package manifest. In an empty directory, run npm init -y first. You will also need a POSIX shell and curl.

npm
pnpm
yarn
bun
npm install -D @decoyhq/cli

Install a standalone binary.

Define the user response

Create a folder for your mock files.

Terminal: create the Route directory
mkdir -p mocks/routes

Save the following Route as mocks/routes/users.yaml. It handles GET /users/{id}. The user-123 Case picks requests for ID 123, and its success Behavior returns Ada.

mocks/routes/users.yaml
id: users-by-id
transport: http
match: { method: GET, path: '/users/{id}' }

cases:
  user-123:
    match: { pathParams: { id: '123' } }

    behaviors:
      success:
        status: 200
        body: { id: '123', name: Ada }

Create a Collection named happy-path so Decoy starts with the success response.

mocks/collections.yaml
- id: happy-path
  routes: [users-by-id:user-123:success]

Request the user

Run the server from the directory containing mocks/. Leave this terminal open. The --watch flag lets you edit the files in the next step.

npm
pnpm
yarn
bun
npm exec --package=@decoyhq/cli -- decoy serve --routes mocks/routes --collections mocks/collections.yaml --port 8080 --watch

If you installed the standalone binary, run the same command starting at decoy serve.

In a second terminal, request the user.

Terminal 2: request the user
curl -i http://localhost:8080/users/123

Look for 200 OK and this response body:

200 OK response body
{ "id": "123", "name": "Ada" }

Switch to a 404

Replace the Route file with this version. It adds a second Behavior named missing beside success.

mocks/routes/users.yaml
id: users-by-id
transport: http
match: { method: GET, path: '/users/{id}' }

cases:
  user-123:
    match: { pathParams: { id: '123' } }

    behaviors:
      success:
        status: 200
        body: { id: '123', name: Ada }

      missing:
        status: 404
        body: not found

Append a second Collection to mocks/collections.yaml. Its Behavior address ends in missing, so the same request now has a different response available.

mocks/collections.yaml (append this entry)
- id: user-missing
  routes: [users-by-id:user-123:missing]

After Decoy reloads the files, switch Collections from the second terminal.

Terminal 2: switch to user-missing
curl -X POST http://localhost:8080/__decoy__/control/useCollection \
  -H 'content-type: application/json' \
  -d '{"collection":"user-missing"}'

Repeat the original request. This time you'll see 404 Not Found and the body not found.

Terminal 2: request the same user again
curl -i http://localhost:8080/users/123

Try a path you haven't mocked:

Terminal 2: request an unmocked path
curl -i http://localhost:8080/orders

Look for 501 Not Implemented and x-mock-miss: true. Decoy tells you what failed to match instead of forwarding the request to a real service. See How mock misses work.

Stop Decoy with Ctrl-C in the server terminal.

To keep these settings in your project, put the flags in decoy.yaml. To match another user, add a Case. To switch this response from a browser test, follow the Playwright or Testplane setup.