Decoy Getting started Docs GitLab Hub

Answer third‑party API calls yourself

Decoy takes over the calls your application makes to outside services, such as a payment provider, and answers them with the responses you define. It records every call, so a test can check what was sent. You do not change the application.

api.stripe.com Intercepted Host
  1. The app calls the real hostname

    $ decoy run -- curl -s -w '\nHTTP %{http_code}\n' -X POST https://api.stripe.com/v1/payment_intents -d amount=1000
  2. A Rule answers. The call never leaves the machine

    {"error":{"code":"card_declined"}}
    HTTP 402
  3. The Call Journal shows what was sent

    {"id":"c2","method":"POST","path":"/v1/payment_intents","outcome":"rule","rule_id":"r1","status":402}
Real output from Getting started, run with the Decoy 0.1.0 release binary.
Intercepted Host
A hostname Decoy takes over, for example api.stripe.com. Every other hostname resolves and connects normally.
Rule
A registered behavior for requests to an Intercepted Host. It matches on host, path, method and headers, and decides the response.
Call Journal
The record of every intercepted request and the response Decoy gave. You query it to assert on what was called.

Why Decoy

  1. Your application keeps calling the real hostname

    The app still calls api.stripe.com. There is no second base URL to configure and no test-only client code. You point the client at Decoy with a proxy setting or with Decoy's DNS, and you make it trust the Decoy CA. That is configuration, not a code change.

    Only the hosts you intercept are affected. Every other host is tunnelled to the real destination untouched.

  2. You choose the answer for each test

    You register Rules at runtime through a local control API. A test can add a Rule that makes a payment return a declined card, run the scenario, and delete that Rule by its label afterwards. Rules can be scoped by header, so parallel scenarios can share one Decoy.

    curl -X POST http://127.0.0.1:7411/rules -d '{
      "label": "demo", "host": "api.stripe.com", "method": "POST",
      "path": {"prefix": "/v1/payment_intents"},
      "respond": {"status": 402, "json": {"error": {"code": "card_declined"}}}
    }'

    When a fixed answer is not enough, a Rule can run code. A Handler is a Workers-style module that receives a request and returns a response:

    export default {
      async fetch(request: Request, env: { decoy: { ruleId: string } }) {
        return Response.json({ error: { type: "card_error", code: "card_declined" } }, { status: 402 });
      },
    };

    Handlers run in a Rule Host, a Node, Bun or Deno process, so npm imports work. With no runtime installed, Embedded Mode runs the same file inside Decoy, without npm imports.

  3. An unexpected call fails loudly

    Each Intercepted Host has an Unmatched Policy for requests that no Rule matches. It can fail with a 502 whose body names the request, forward the request to the real service, or answer with a canned response. The default is to fail, so a call you did not plan for shows up instead of quietly reaching the real service.

  4. You can see what your app sent

    The Call Journal keeps each intercepted request and the answer Decoy gave. Filter it by host, method, path, header, Rule or outcome. Read back only the calls since you last looked.

  5. One binary, set up for the client you have

    Decoy is one binary. It is the DNS server and the HTTP(S) proxy, and it mints certificates for Intercepted Hosts from its own CA the first time they are needed. Setup Helpers point a client at Decoy and make it trust the CA:

    • decoy run -- <command> starts one command with the proxy and trust settings.
    • decoy setup browser prints browser proxy and trust settings.
    • decoy setup docker and decoy setup kubernetes write Compose and ConfigMap settings.

    There are two ways to reach Decoy. In Proxy Mode the client uses Decoy as its HTTP(S) proxy. In Transparent Mode the client uses Decoy's DNS, so an Intercepted Host resolves to Decoy and no proxy setting is needed.

Works with Hunt and Jetlag

Decoy runs on its own. These two SlopKit products use it.

Limits

Answer your first call

Download the binary, intercept api.stripe.com, register a Rule, and read the call back from the Call Journal. No account and no Nix. The reference covers the control API, Rules, Handlers, Setup Helpers and flags.

mkdir -p ~/.local/bin
curl -fsSL -o ~/.local/bin/decoy "https://gitlab.techtailors.net/api/v4/projects/slopkit%2Fdecoy/packages/generic/decoy/0.1.0/decoy-linux-amd64"
chmod +x ~/.local/bin/decoy
decoy --version