# Decoy ## Others - [Collections](/docs/collections/index.md): A Collection lists the Behaviors that are active together for a Scenario. All Collections live in one YAML file. Each entry is a Behavior address, route:case:behavior. The structured form { route: users-by-id, case: user-1, behavior: ada } works too. There are no implicit defaults: a Route whose Cases aren't listed is not active.from inherits another Collection. A child entry for the same route+case replaces the parent's.The first Collection is the default. Override it at startup with decoy serve --collection (or collection: in the config file), or at runtime per Session with the Control API. - [Configuration](/docs/config/index.md): decoy serve takes flags, a YAML config file, or both. Flags win over the file. If you've followed the quick start, save this next to collections.yaml to keep the same settings without repeating the flags: From the project directory, run: Add a one-off flag such as --port 8081 to override the file without editing it. - [Runnable examples](/docs/examples/index.md): Each example includes mock files and a client or test suite you can run from the Decoy repository. For workspace setup and the command to run every example, see Contributing. - [gRPC](/docs/grpc/index.md): Decoy answers unary and server-streaming gRPC calls on its normal port. gRPC over HTTP/2 cleartext (h2c), plain HTTP, and the Control API all share it. Point your gRPC client at Decoy instead of the real service; no generated code or server stubs are needed. Client and bidi streaming are not supported yet. For gRPC over TLS, turn on TLS; the same port then speaks gRPC over HTTPS. - [Decoy documentation](/docs/index.md): Serve a mock locally, switch responses in a running app, and isolate parallel tests. - [Install](/docs/install/index.md): Decoy is one native binary, decoy. Pick the channel that fits your project. - [Playwright](/docs/playwright/index.md): @decoyhq/playwright routes your browser's API calls to decoy, gives each test its own Session, and exposes the Control API as a fixture. Next, switch responses in a test. For a page that opens a socket, bridge browser WebSockets. - [Switch responses in a test](/docs/playwright/responses/index.md): Use the decoy fixture to select a Collection before the page makes its request. This test selects no-users and checks the error that the page renders. - [Bridge browser WebSockets](/docs/playwright/websockets/index.md): Set webSocketUrls to route the page's own sockets to Decoy (Playwright 1.48 or later). The page needs no changes: Each matching page socket is bridged to Decoy: the fixture opens its own socket to Decoy at the same path and query (ws://, or wss:// for an https url) with x-mock-session set to the test's Session. Text and binary frames pass both ways; when either side closes, the other is closed too, with the same code and reason where the protocol allows it. When the test ends, the fixture closes its sockets to Decoy that are still open.The real server is never contacted. If Decoy can't be reached, the page socket is closed.A socket keeps the Session it opened with; see WebSocket for Routes and Behaviors. To push a message from the test, wait for the page's socket and send to it: decoy.connection(route, { timeout }) resolves once this test's Session has a live connection on the Route (Control API wait). It rejects on timeout (Decoy's default when timeout is unset), for an unknown Route, or for a Route whose transport has no connections (HTTP, unary gRPC)..send(message) pushes message to every live connection of the Route in this Session, skipping Cases (Control API send). Other tests' sockets never get it.It resolves while any of the Session's sockets on the Route is live, including one that is closing. After a reload, wait for a page signal that the new socket is up before you send. - [Serve your first mock](/docs/quick-start/index.md): Return a user, then change the same request to a 404 while Decoy is running. - [Routes, Cases, and Behaviors](/docs/routes/index.md): A Route is one YAML file with an id, one transport, and a match saying where the interaction happens. Its Cases say which request shape matched, and each Case owns named Behaviors: what Decoy does. Decoy loads every .yaml/.yml file under the routes directory, recursively, so you can group files in folders. Duplicate Route ids fail startup. - [Sessions and the Control API](/docs/sessions-and-control/index.md) - [Glossary](/docs/terms/index.md): Understand the names you see in Decoy mock files, requests, and tests. - [Testplane](/docs/testplane/index.md): @decoyhq/testplane is a Testplane plugin. It starts decoy for the run, gives each test its own Session, routes the browser's API calls to Decoy, and exposes the Control API as decoy(browser). The setup is one plugins entry: Next, switch responses in a test. - [Switch responses in a test](/docs/testplane/responses/index.md): Use decoy(browser) to select a Collection before the page makes its request. This test selects no-users and checks the error that the page renders. - [TLS](/docs/tls/index.md): Some clients only talk HTTPS: a BFF that must call its backends over TLS, an app served over https in the browser, a gRPC client using TLS credentials. Decoy can serve any listener over TLS, and keep others plain http next to it. - [Configure a Transformer Pipeline](/docs/transformer-pipelines/index.md): Define a Transformer once in decoy.yaml to reuse it across named Pipelines. In the example below, gzip runs a command and approvals uses a persistent worker. The approvals-feed Pipeline decompresses incoming data before passing it to the worker. On output, it runs the worker first and compresses the result. - [@decoyhq/transformer](/docs/transformer-sdk/index.md): Write Decoy Transformer workers in TypeScript. A worker can turn an app's wire format (msgpack envelopes, binary headers in front of protobuf, compression) into the JSON that Cases match and Behaviors render, and back. HTTP, gRPC, and WebSocket Routes can use workers. See Configure a Transformer Pipeline for setup. This example adapts binary and text WebSocket messages. Save it as workers/envelope.ts: Register the worker and name its Pipeline in decoy.yaml: defineTransformer returns the transformer, and serves it over stdin/stdout when Decoy started the process (DECOY_TRANSFORMER=1). A unit test can import the file and call input directly.A package can export a factory that takes typed options and returns defineTransformer(...); users call it from their own worker file.On WebSockets, miss(reason) in input skips the frame: Decoy logs the reason and keeps the socket open. Any other throw is a worker error, shown with the Transformer, Behavior and value that failed.WebSocket input sets ctx.frame to 'text' or 'binary'. WebSocket input and output supply ctx.connection as { id, route, session } and share a ctx.state map per connection. HTTP, gRPC and startup checks get a fresh state map for each call.HTTP workers receive ctx.request on input and output, including Passthrough output. It is a read-only snapshot of the original method, path, and headers (lowercase names). The headers can include cookies and credentials; avoid logging them. Startup checks have no request context.ctx.protobuf.has/decode/encode use the protos Decoy already compiled.console.log goes to stderr while serving, since stdout carries the protocol. Decoy prints each stderr line with the worker's label. To implement a worker in another language, see the wire protocol. - [Transformer worker protocol, version 1](/docs/transformer-worker-protocol/index.md): Use this specification to write a Transformer worker in another language. It describes the messages exchanged by Decoy and the TypeScript SDK. To configure a worker for a Route, see Configure a Transformer Pipeline. - [Transformers](/docs/transformers/index.md): A Transformer takes a value and produces another. For example, it might extract an ID from an object, decompress bytes, or turn a timestamp into a date string. HTTP, gRPC, and WebSocket Routes can all use Transformers. A Pipeline chains them: each step receives the previous step’s result. The input and output directions have separate lists, so you can choose a different conversion for each direction. - [Troubleshoot a mock](/docs/troubleshooting/index.md): Start with what your client saw: no connection, a mock miss, or a valid response you didn't expect. - [Terminal UI](/docs/tui/index.md): Run decoy with no subcommand to start the server with an interactive log of every request. It takes the same flags as decoy serve. Type / to run a command. Commands act on the active Session, which is default until you pick another with /session. - [WebSocket](/docs/websocket/index.md): Decoy accepts WebSocket upgrades on its normal port, next to plain HTTP, gRPC and the Control API. Point the client's socket URL at Decoy. With TLS on, the same port serves wss://. Supported so far: text frames carrying JSON or plain text, on: connect Cases, timed replies, close, Control API send, and binary formats through WebSocket Pipelines.