Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Mock APIs (OpenAPI)

Upload an OpenAPI document and Rustybin serves it as a named mock API at /mock/<name>: every operation answers with a response that matches the spec, every call is captured, and security from the spec (API keys, basic, bearer, OAuth 2.0 scopes, mTLS) can be switched on in front of it. Point a gateway at the mock URL and you have a realistic upstream for an API that does not exist yet, or that you cannot reach from a demo laptop.

  • An AsyncAPI document makes an event mock in the same list: channels served over WebSocket, server-sent events and webhooks in place of operations.
  • OpenAPI 3.0 and 3.1, as JSON or YAML, one bundled file (local #/... references only; external $refs are refused with a clear message). Swagger 2.0 is converted to OpenAPI 3.0 on import, with a warning saying so.
  • Responses come from the spec's examples or are generated from the schemas, deterministically, with path parameters echoed (GET /pets/42 returns "id": 42). Rules, overrides and the Prefer header pick other documented responses. See Responses, rules and validation.
  • Requests are validated against the spec (warn by default, or enforce with 400).
  • Every deployed mock is also an MCP server at /mock/<name>/_rustybin/mcp, one tool per operation, answered by the same mock. See An MCP server for every mock.
  • Publish a mock to the dev portal at /portal: testers read its reference, try it, download collections and copy its MCP snippets without the console.
  • Each mock has a draft and a live revision: edits are checked (a valid request and response per operation) before they are deployed, and a deploy can be rolled back.
  • Mocks are created in the web console, through the control API, from a rustybin.yaml file or a directory of specs at startup (Configuration as code), or with the rustybin mock CLI.

Mocks created in the console or through the API are saved when RUSTYBIN_STATE_DIR (or RUSTYBIN_MOCKS_STATE_DIR) points to a writable directory. Without it, they live in memory and are lost on restart. Mocks declared in files are recreated at startup. Use export and apply for a portable rustybin.yaml; see persistence.

Quick start

In the console

  1. Open /ui/#/mocks (for example http://localhost:8080/ui/#/mocks).
  2. Drop an OpenAPI file on the page, or paste it. Rustybin parses it at once and shows the operations, the security schemes and any warnings, with a name derived from info.title.
  3. Choose how responses are produced (spec examples, generated data, or your own), whether to secure the mock and whether to validate requests, then Create and deploy.
  4. Copy the mock URL (or the ready curl command) into your gateway. The mock's Traffic tab shows each call as it arrives.

With the API

POST /_rustybin/mocks takes the spec (a JSON object, or the document text) and optional settings, runs the deploy checks and makes the mock live (201). The example runner uses an open control plane and an admin token. On a default instance, use a token from sign-in, which also satisfies the admin guard:

POST {{base_url}}/_rustybin/mocks
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{
  "name": "docs-orders",
  "spec": {
    "openapi": "3.0.3",
    "info": {"title": "Orders API", "version": "1.0"},
    "servers": [{"url": "https://orders.example.com/api"}],
    "paths": {
      "/orders": {
        "get": {
          "operationId": "listOrders",
          "responses": {"200": {"description": "Orders", "content": {"application/json": {
            "schema": {"type": "array", "maxItems": 2, "items": {"$ref": "#/components/schemas/Order"}}}}}}
        }
      },
      "/orders/{orderId}": {
        "get": {
          "operationId": "getOrder",
          "parameters": [{"name": "orderId", "in": "path", "required": true, "schema": {"type": "integer"}}],
          "responses": {"200": {"description": "An order", "content": {"application/json": {
            "schema": {"$ref": "#/components/schemas/Order"}}}}}
        }
      }
    },
    "components": {"schemas": {"Order": {
      "type": "object", "required": ["orderId", "total"],
      "properties": {
        "orderId": {"type": "integer"},
        "total": {"type": "number", "minimum": 0},
        "currency": {"type": "string", "enum": ["EUR", "USD"]}
      }
    }}}
  }
}
HTTP 201
[Asserts]
jsonpath "$.name" == "docs-orders"
jsonpath "$.state" == "live"
jsonpath "$.origin" == "api"
jsonpath "$.url" == "{{base_url}}/mock/docs-orders/api"
jsonpath "$.report.ok" == true
jsonpath "$.operations" count == 2
GET {{base_url}}/mock/docs-orders/api/orders/7
HTTP 200
[Asserts]
header "X-Rustybin-Mock-Operation" == "getOrder"
jsonpath "$.orderId" == 7
jsonpath "$.total" isNumber
FieldDefaultMeaning
specrequiredThe OpenAPI document: an object, or JSON / YAML text
nameslug of info.title1 to 40 characters a-z, 0-9 and -, not at either end; import, export, apply, reload, visit, visits and ai are reserved. A taken default gets a -2, -3, ... suffix; a taken explicit name is a 409.
deploytrueRun the checks and make the draft live. false creates a draft only (its URL answers 503 until deployed).
forcefalseDeploy even when the checks report errors
enabledtrueThe on/off switch
strip_server_prefix, responses, security, operationsdefaultsThe mock's settings, the same structure as in rustybin.yaml

A deploy that the checks refuse answers 422 with the report; an invalid spec or invalid settings answer 400 with a message.

POST /_rustybin/mocks/import parses a spec without creating anything and returns what the console's wizard shows: title, version, suggested (free) name, server prefix, operations, security schemes, warnings and a check summary. The body is {"spec": ...} or the document itself (JSON or YAML text):

# A preview: nothing is created. The body may also be the spec itself
# (JSON or YAML text).
POST {{base_url}}/_rustybin/mocks/import
Content-Type: application/json
{
  "spec": {
    "openapi": "3.0.3",
    "info": {"title": "Orders API", "version": "1.0"},
    "servers": [{"url": "https://orders.example.com/api"}],
    "paths": {
      "/orders/{orderId}": {
        "get": {
          "operationId": "getOrder",
          "parameters": [{"name": "orderId", "in": "path", "required": true, "schema": {"type": "integer"}}],
          "responses": {"200": {"description": "An order"}}
        }
      }
    }
  }
}
HTTP 200
[Asserts]
jsonpath "$.title" == "Orders API"
jsonpath "$.suggested_name" == "orders-api"
jsonpath "$.server_prefix" == "/api"
jsonpath "$.operations[0].id" == "getOrder"
jsonpath "$.operations[0].method" == "GET"
jsonpath "$.declares_security" == false
jsonpath "$.report.ok" == true

With the CLI

rustybin mock validate openapi.yaml                    # offline: parse and check
rustybin mock init openapi.yaml --name orders > rustybin.yaml
rustybin mock push --server http://localhost:8080 --token change-me
curl http://localhost:8080/mock/orders/...

See CLI for every subcommand.

A spec from a URL

A caller that holds a link rather than the file, an agent above all, can have the instance fetch it: spec_url on POST /_rustybin/mocks and on the create_mock tool, rustybin mocks create orders --spec-url <url>, and Or fetch it in the console's new mock dialog, which reads the text first through POST /_rustybin/mocks/import/fetch.

The instance reaches out on the caller's word, so it needs mocks.write, which a visitor of a public instance never holds, and the host has to be in RUSTYBIN_EGRESS_ALLOW (purpose spec_fetch, which has no default). Redirects are not followed, and at most the spec limit is read. A document in rustybin.yaml has no spec_url: applying a file never reaches out.

# The host is not in RUSTYBIN_EGRESS_ALLOW, so nothing is fetched.
POST {{base_url}}/_rustybin/mocks/import/fetch
X-Rustybin-Admin-Token: {{admin_token}}
{"url": "https://specs.example.com/orders.yaml"}
HTTP 403
[Asserts]
jsonpath "$.reason" == "egress_refused"
jsonpath "$.purpose" == "spec_fetch"

The built-in sample

Every instance starts with a petstore mock (src/mocks/petstore.yaml, OpenAPI 3.0, server prefix /v1), so there is something to call on first run. It is not created in public mode; set RUSTYBIN_MOCKS_SAMPLE=false (or true) to change that. It answers from its examples, generates the pets that have none, and has one rule: pet id 0 answers the documented 404.

GET {{base_url}}/mock/petstore/v1/pets
HTTP 200
[Asserts]
header "Content-Type" == "application/json"
header "X-Rustybin-Mock" == "petstore"
header "X-Rustybin-Mock-Operation" == "listPets"
header "X-Rustybin-Mock-Source" == "example:three"
header "X-Total-Count" == "3"
jsonpath "$" count == 3
jsonpath "$[0].name" == "Rex"
# No example for this 200: the body is generated from the Pet schema, and
# `id` echoes the path parameter.
GET {{base_url}}/mock/petstore/v1/pets/42
HTTP 200
[Asserts]
header "X-Rustybin-Mock-Operation" == "getPetById"
header "X-Rustybin-Mock-Source" == "generated"
jsonpath "$.id" == 42
jsonpath "$.name" isString
jsonpath "$.status" matches /^(available|pending|sold)$/
# The sample ships one rule: petId 0 answers the spec's 404 example.
GET {{base_url}}/mock/petstore/v1/pets/0
HTTP 404
[Asserts]
header "X-Rustybin-Mock-Source" == "rule:unknown pet example:notFound"
jsonpath "$.message" == "pet not found"
GET {{base_url}}/mock/petstore/v1/pets/1
Prefer: code=404
HTTP 404
[Asserts]
header "X-Rustybin-Mock-Source" == "prefer example:notFound"
jsonpath "$.code" == 404
POST {{base_url}}/mock/petstore/v1/pets
Content-Type: application/json
{"name": "Rex", "tag": "dog"}
HTTP 201
[Asserts]
header "Location" == "/v1/pets/4"
header "X-Rustybin-Mock-Validation" not exists
jsonpath "$.id" == 4

The sample can be edited, switched off and switched back on like any other mock; it is left out of GET /_rustybin/mocks/export (export it by name if you want a copy). Restarting the instance restores it.

URLs

URLWhat it is
/mock/{name}{prefix}{path}An operation of the mock: {path} is the spec path with its parameters filled in, {prefix} the path of the spec's first server URL (/v1 for servers: [{url: https://api.example.com/v1}], empty without servers). Any method.
/mock/{name}/_rustybin/openapi.json and .yamlThe deployed spec, with servers rewritten to the mock URL, ready to import into a gateway or an API client

strip_server_prefix: true serves the paths without the prefix (/mock/orders/orders/7 instead of /mock/orders/api/orders/7). Server URL variables are replaced by their defaults. The two spec URLs win over the operations (a spec path /_rustybin/openapi.json cannot be mocked) and are not captured.

What a mock URL answers when no operation responds, as application/problem+json and captured in the mock's traffic (except for an unknown name, which has no mock to capture it):

SituationStatus
No mock with that name404 {"error": "mock not found", ...}
Mock created but never deployed503
Mock switched off503, or responses.disabled_status (any 4xx or 5xx, for example 404)
No operation matches the path404, with the mock's base_path
The path matches but not the method405 with Allow
GET {{base_url}}/mock/petstore/v1/owners
HTTP 404
[Asserts]
header "Content-Type" == "application/problem+json"
jsonpath "$.detail" == "no operation of this mock matches GET /v1/owners"
jsonpath "$.base_path" == "/mock/petstore/v1"

PATCH {{base_url}}/mock/petstore/v1/pets
HTTP 405
[Asserts]
header "Allow" == "GET, POST"

GET {{base_url}}/mock/no-such-mock/anything
HTTP 404
[Asserts]
jsonpath "$.error" == "mock not found"
GET {{base_url}}/mock/petstore/_rustybin/openapi.json
HTTP 200
[Asserts]
jsonpath "$.info.title" == "Petstore"
jsonpath "$.servers" count == 1
jsonpath "$.servers[0].url" == "{{base_url}}/mock/petstore/v1"

GET {{base_url}}/mock/petstore/_rustybin/openapi.yaml
HTTP 200
[Asserts]
header "Content-Type" == "application/yaml"
body contains "url: {{base_url}}/mock/petstore/v1"

Every mock response carries X-Rustybin-Mock: <name>, and once an operation matched X-Rustybin-Mock-Operation: <operationId> (a stable id such as get_orders_id is made up when the spec has none). Successful mock responses also carry X-Rustybin-Mock-Source (how the response was chosen) and, when the request did not match the spec, X-Rustybin-Mock-Validation: failed. All four are exposed to browsers through CORS.

Fault injection (X-Rustybin-Delay, X-Rustybin-Fail) works on mocks like on every data-plane route.

Listing and inspecting mocks

GET {{base_url}}/_rustybin/mocks
HTTP 200
[Asserts]
jsonpath "$.mocks[*].name" contains "petstore"
jsonpath "$.limits.max_mocks" == 100
jsonpath "$.load_errors" isCollection

# With the admin token the details include the demo credentials (without it
# they are "<redacted>").
GET {{base_url}}/_rustybin/mocks/petstore
Authorization: Bearer {{admin_token}}
HTTP 200
[Asserts]
jsonpath "$.state" == "live"
jsonpath "$.origin" == "sample"
jsonpath "$.url" == "{{base_url}}/mock/petstore/v1"
jsonpath "$.spec.server_prefix" == "/v1"
jsonpath "$.operations[*].id" contains "getPetById"
jsonpath "$.credentials.api_key.keys[0]" == "demo-key"

The list gives, per mock: name, url, title, version, state (live, off or draft when never deployed), enabled, has_draft_changes, origin (api, file or sample), the operation count, security (enabled and mode), response mode, validate_requests, requests_total, last_hit, the live and draft revision numbers, a check summary and expires_at (public mode). It also returns the instance limits and load_errors (problems from rustybin.yaml or the mocks directory).

GET /_rustybin/mocks/{name} adds the draft's details: the spec summary and its warnings, the settings, every operation (method, path, statuses, whether it is secured, where its response comes from, its check status), the demo credentials, the deploy report summary and the revisions.

Draft, deploy, rollback

Every change (PATCH /_rustybin/mocks/{name}, PUT .../operations/{op}) goes to the mock's draft; the live revision keeps answering until you deploy. PATCH takes name (rename: the old URL stops working), spec (replace the document), strip_server_prefix, responses, security and operations. Each given section replaces the draft's section as a whole (a responses object without mode resets the mode to examples); sections you leave out are kept. "deploy": true publishes in the same call.

# Edits go to the draft: the live revision keeps answering until a deploy.
PATCH {{base_url}}/_rustybin/mocks/docs-orders
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{"strip_server_prefix": true}
HTTP 200
[Captures]
draft: jsonpath "$.draft_revision"
[Asserts]
jsonpath "$.state" == "live"
jsonpath "$.has_draft_changes" == true
jsonpath "$.revisions[0].draft" == true

GET {{base_url}}/mock/docs-orders/api/orders/7
HTTP 200

# Deploy the draft just read: If-Match (or expected_revision in the body)
# refuses with 409 a draft someone changed since.
POST {{base_url}}/_rustybin/mocks/docs-orders/deploy
Authorization: Bearer {{admin_token}}
If-Match: "{{draft}}"
HTTP 200
[Asserts]
jsonpath "$.deployed" == true
jsonpath "$.report.ok" == true
jsonpath "$.mock.has_draft_changes" == false

# The server prefix (/api) is gone from the mock URL.
GET {{base_url}}/mock/docs-orders/orders/7
HTTP 200
[Asserts]
jsonpath "$.orderId" == 7

POST /_rustybin/mocks/{name}/deploy runs the deploy checks on the draft and swaps it in atomically; check errors answer 422 with the report unless you add ?force=true. Deploying an unchanged draft is a no-op. The previous live revisions are kept (5, 2 in public mode): POST .../rollback makes the previous one live again, or the one named in {"revision": n} (revision numbers come from the details' revisions list). The draft follows the rollback.

POST {{base_url}}/_rustybin/mocks/docs-orders/rollback
Authorization: Bearer {{admin_token}}
HTTP 200
[Asserts]
jsonpath "$.rolled_back" == true

GET {{base_url}}/mock/docs-orders/api/orders/7
HTTP 200

Two people editing one mock

Every mock answer carries its draft_revision, and GET /_rustybin/mocks/{name} (and the operation's GET) sends it as the ETag. An edit that names the revision it was made from, as If-Match: "12" or "expected_revision": 12 in the body, is refused with 409 when the draft has moved on since. The answer names the current revision and what changed (the spec, the responses, an operation), and nothing is saved: read the mock again, then edit. A deploy can name the revision it publishes the same way (If-Match or {"expected_revision": 12} on POST .../deploy): a draft changed since is refused with 409 and nothing goes live. PATCH with "deploy": true always publishes the revision it just wrote. Revision numbers keep growing across restarts (a new process starts counting from the clock), so a revision read before a restart never matches a draft compiled after it.

# Read the mock: its ETag is the draft revision.
GET {{base_url}}/_rustybin/mocks/docs-orders
Authorization: Bearer {{admin_token}}
HTTP 200
[Captures]
revision: jsonpath "$.draft_revision"
[Asserts]
header "ETag" exists

# An edit from that revision passes.
PATCH {{base_url}}/_rustybin/mocks/docs-orders
Authorization: Bearer {{admin_token}}
If-Match: "{{revision}}"
Content-Type: application/json
{"responses": {"mode": "generated"}}
HTTP 200

# A second edit from the same revision is refused: someone changed the mock.
PUT {{base_url}}/_rustybin/mocks/docs-orders/operations/listOrders
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{"delay_ms": 100, "expected_revision": {{revision}}}
HTTP 409
[Asserts]
jsonpath "$.error" == "rustybin_stale_revision"
jsonpath "$.expected_revision" == {{revision}}
jsonpath "$.current_revision" > {{revision}}
jsonpath "$.changed" contains "responses"

# A deploy naming that revision is refused too: the draft is not what was read.
POST {{base_url}}/_rustybin/mocks/docs-orders/deploy
Authorization: Bearer {{admin_token}}
If-Match: "{{revision}}"
HTTP 409
[Asserts]
jsonpath "$.error" == "rustybin_stale_revision"

The console, the CLI (--expect-revision, else the revision it reads just before the edit) and the management tools (expected_revision on update_mock and set_operation) always send one. A plain API call without one is accepted, and an edit that raced another without naming a revision is made again on top of it rather than lost. The setting mocks.require_revision (Management, General) makes the revision mandatory for every caller: an edit without one answers 428.

SurfaceWhere
APIIf-Match or expected_revision on PATCH /_rustybin/mocks/{name}, PUT /_rustybin/mocks/{name}/operations/{op} and POST /_rustybin/mocks/{name}/deploy; the ETag on the mock and its operations; GET /_rustybin/mocks/{name}/revisions/{revision}
ConsoleSent with every edit and deploy; a refused edit opens the compare view (Keep mine, Take theirs); a refused deploy says what changed and offers to reload
CLIrustybin mocks update and mocks set-operation with --expect-revision N (default: read just before); mocks deploy --expect-revision N (default: the draft as it is); mocks revision NAME N
Management MCPexpected_revision on update_mock, set_operation and deploy_mock; get_mock_revision
rustybin.yamlsettings: { mocks.require_revision: true } (kept revisions are not part of a document: they are the store's memory)

Comparing a refused edit

GET /_rustybin/mocks/{name}/revisions/{revision} answers a revision the store still keeps: the draft, the live revision, the last deployed ones (5, 2 in public mode) and as many drafts that were replaced before anyone deployed them. Drafts and deployed revisions share one numbering, so the expected_revision of a 409 is a revision you can read here (until it is pushed out). The answer holds the spec as uploaded (spec.text), the settings (secrets redacted unless you may change the mock), whether it is the draft or live, and changes_to_draft: the sections the current draft changes since, the same list as the 409's changed. A revision no longer kept is 404, and so is another visitor's mock (it is read like the mock itself). Kept revisions live in memory: after a restart only the saved draft and live revision are there.

# What the other change did: the revision the refused edit was made from,
# its spec and settings, and what the draft changed since.
GET {{base_url}}/_rustybin/mocks/docs-orders/revisions/{{revision}}
Authorization: Bearer {{admin_token}}
HTTP 200
[Asserts]
jsonpath "$.revision" == {{revision}}
jsonpath "$.draft" == false
jsonpath "$.settings.responses.mode" != "generated"
jsonpath "$.changes_to_draft" contains "responses"
jsonpath "$.spec.text" contains "/orders"

# Keep mine: the refused edit again, naming the current draft revision.
GET {{base_url}}/_rustybin/mocks/docs-orders
Authorization: Bearer {{admin_token}}
HTTP 200
[Captures]
current: jsonpath "$.draft_revision"

PUT {{base_url}}/_rustybin/mocks/docs-orders/operations/listOrders
Authorization: Bearer {{admin_token}}
If-Match: "{{current}}"
Content-Type: application/json
{"delay_ms": 100}
HTTP 200
[Asserts]
jsonpath "$.settings.delay_ms" == 100

# A revision no longer kept answers 404.
GET {{base_url}}/_rustybin/mocks/docs-orders/revisions/1
Authorization: Bearer {{admin_token}}
HTTP 404

In the console a refused edit opens a compare dialog instead of a plain refusal. Per section (the spec, the responses, security, the MCP server, each operation's settings, rules and examples) it shows what the other change did, from the revision the edit was made from to the current draft, beside the edit that was refused, from the same revision, each as a line diff. A badge says what saving yours does to the section: your edit, their change stays, or changed on both sides (yours replaces theirs). Keep mine sends the refused edit again naming the current revision: the sections it sets replace theirs and the rest of their change stays (an operation editor's save touches that one operation only). Take theirs reloads the page with their version. Close (or Escape) keeps your form as it is, nothing saved. When the revision the edit was made from is no longer kept, each section shows the current draft changed into your edit. Every action is a button reached with Tab; the dialog keeps the focus until it closes.

SurfaceWhere
APIGET /_rustybin/mocks/{name}/revisions/{revision}
ConsoleThe compare dialog of a refused edit (Settings, an operation's editor, the security panel)
CLIrustybin mocks revision orders 12 (a summary; --json the whole answer, --spec the spec only)
Management MCPget_mock_revision (name, revision), then update_mock or set_operation with the current expected_revision
rustybin.yamlNothing: kept revisions are not configuration

On and off

POST .../disable switches a mock off without losing its configuration or traffic: its URL answers 503 (or responses.disabled_status), which gives gateway health checks and circuit breakers something to react to. POST .../enable switches it back on. DELETE /_rustybin/mocks/{name} removes the mock and its traffic.

POST {{base_url}}/_rustybin/mocks/docs-orders/disable
Authorization: Bearer {{admin_token}}
HTTP 200
[Asserts]
jsonpath "$.state" == "off"

GET {{base_url}}/mock/docs-orders/api/orders/7
HTTP 503
[Asserts]
header "Content-Type" == "application/problem+json"
jsonpath "$.detail" == "this mock is switched off"
jsonpath "$.mock" == "docs-orders"

POST {{base_url}}/_rustybin/mocks/docs-orders/enable
Authorization: Bearer {{admin_token}}
HTTP 200
[Asserts]
jsonpath "$.state" == "live"

GET {{base_url}}/mock/docs-orders/api/orders/7
HTTP 200
DELETE {{base_url}}/_rustybin/mocks/docs-orders
Authorization: Bearer {{admin_token}}
HTTP 200
[Asserts]
jsonpath "$.deleted" == "docs-orders"

GET {{base_url}}/mock/docs-orders/api/orders/7
HTTP 404

Traffic

Every call to a mock is captured, including the ones answered with 401, 400, 404, 405 or 503: method, path below the mock (path) and full path, query, headers, client IP, body (up to 64 KiB), the outcome (mocked, unauthorized, forbidden, invalid_request, not_found, method_not_allowed, disabled, not_deployed), the matched operation, the live revision, the response source, the validation issues, the auth result, the status, the response headers and body, and the duration.

GET {{base_url}}/_rustybin/mocks/docs-orders/requests
HTTP 200
[Asserts]
jsonpath "$.total" == 1
jsonpath "$.requests[0].method" == "GET"
jsonpath "$.requests[0].path" == "/api/orders/7"
jsonpath "$.requests[0].outcome" == "mocked"
jsonpath "$.requests[0].operation" == "getOrder"
jsonpath "$.requests[0].status" == 200
jsonpath "$.requests[0].validation" isEmpty
jsonpath "$.requests[0].response_body" contains "\"orderId\": 7"
[Captures]
seq: jsonpath "$.requests[0].seq"

GET {{base_url}}/_rustybin/mocks/docs-orders/requests/{{seq}}
HTTP 200
[Asserts]
jsonpath "$.full_path" == "/mock/docs-orders/api/orders/7"
RouteReturns
GET /_rustybin/mocks/{name}/requestsCaptured requests, newest first (?limit=, default 50)
GET /_rustybin/mocks/{name}/requests/{n}One request by sequence number
GET /_rustybin/mocks/{name}/requests/streamLive feed (Server-Sent Events, one request event per call, Last-Event-ID replays)
DELETE /_rustybin/mocks/{name}/requestsClear the captures (admin)

The oldest captures are evicted first when the log is full (see the limits below). Mock calls also appear in the request inspector like any other data-plane request.

Control-plane protection

Mock management lives on the control plane (/_rustybin/mocks*); the mocks themselves (/mock/*) are data plane and never need a control-plane token.

  • Every change (create, PATCH, PUT, deploy, rollback, enable, disable, delete, apply, reload, clearing traffic) follows the admin token rules: with RUSTYBIN_ADMIN_TOKEN set it needs Authorization: Bearer <token> or X-Rustybin-Admin-Token; without one it is open, except in public mode where it is refused (403), so a public instance is read-only for mocks, unless self-service mocks let visitors manage their own.
  • With control-plane authentication (RUSTYBIN_CONTROL_AUTH=password, the default, token or jwt), reading needs mocks.read (the viewer role, the console scope), changing a mock mocks.write, deleting one mocks.delete and resetting its data mocks.data (the editor and admin roles); the read-only POST routes import, .../validate and .../rules/test need mocks.read, a mock's traffic traffic.read, and applying a document or reloading the files config.apply (see permissions).
  • Mock secrets (API keys, bearer tokens, basic passwords) are only shown to callers who may change mocks; everyone else gets placeholders (hidden secrets).
# The run.sh server has an admin token: mutations without it are refused.
POST {{base_url}}/_rustybin/mocks/docs-orders/disable
HTTP 401
# Secured instance (control auth jwt): a console token reads mocks...
GET {{secured_url}}/_rustybin/mocks
Authorization: Bearer {{console_token}}
HTTP 200
[Asserts]
jsonpath "$.mocks[*].name" contains "petstore"

# ...but cannot change them (a change needs mocks.write, which the console
# scope does not grant).
POST {{secured_url}}/_rustybin/mocks/petstore/disable
Authorization: Bearer {{console_token}}
HTTP 403
[Asserts]
jsonpath "$.reason" == "permission_required"
jsonpath "$.permission" == "mocks.write"

# The mocks themselves are data plane: no token.
GET {{secured_url}}/mock/petstore/v1/pets
HTTP 200

Limits

NormalPublic mode
Mocks per instance (sample and file mocks included)10050
Spec size1 MiB256 KiB
Operations per mock500200
Rules per operation2010
Configured response body256 KiB64 KiB
Previous revisions kept for rollback52
Captured requests per mock200 (1 MiB)50 (256 KiB)
Captured request body64 KiB64 KiB
Stateful data per mock1,000 items, 2 MiB200 items, 256 KiB
delay_ms30 s10 s
Lifetime of mocks created through the console or APIunlimited24 hours

Mocks from rustybin.yaml, the mocks directory and the sample never expire. Other fixed caps: 20 headers per configured response, matches patterns up to 256 characters, 50 API keys, bearer tokens and basic users per mock, $ref chains up to 32 deep, a rustybin.yaml up to 8 MiB and 200 files in the mocks directory. Generated strings are padded to minLength up to 64 KiB (a larger minimum gives a value that fails its own schema, which the deploy checks report), one generated value holds at most 1 MiB of string content (past it strings stay short and the rest is null), and one request validation makes at most 500,000 schema checks (uniqueItems counts one per item). A path template may name a parameter once, hold at most 32 of them and contain no whitespace or control character (other paths are skipped with a warning), a server URL is at most 2 KiB once its variables are filled in (else servers[0] is ignored with a warning), and a sample request cuts a path value at 1 KiB. Parsing and compiling a spec (preview, create, edits, operation settings, samples, duplicates, AI previews and generated examples) runs off the request threads, four at a time: past five seconds of waiting the answer is 503 with Retry-After, and a caller without admin rights gets 30 compiles a minute (429 past it): a visitor's per visit, an API key's per key, and a caller without a manage token per address (a new session header per request does not reset it). A visitor's creation past the caps is refused before its spec is compiled. GET /_rustybin/mocks returns the instance's limits as limits.

Control API

RoutePurpose
GET /_rustybin/mocksList mocks, limits and load errors
POST /_rustybin/mocksCreate (admin)
POST /_rustybin/mocks/importPreview a spec, create nothing
GET /_rustybin/mocks/{name}Details of the draft, revisions, credentials
PATCH /_rustybin/mocks/{name}Edit the draft (admin)
DELETE /_rustybin/mocks/{name}Delete (admin)
POST /_rustybin/mocks/{name}/enable, .../disableThe on/off switch (admin)
POST /_rustybin/mocks/{name}/deployCheck and publish the draft, ?force=true (admin)
POST /_rustybin/mocks/{name}/rollbackPrevious revision, or {"revision": n} (admin)
GET /_rustybin/mocks/{name}/reportDeploy checks of the draft
GET /_rustybin/mocks/{name}/specThe draft's spec as uploaded (JSON or YAML as written)
GET /_rustybin/mocks/{name}/revisions/{revision}A kept revision: its spec, settings and what the draft changed since
POST /_rustybin/mocks/{name}/duplicateCopy the mock, {"name": ...} optional (default <name>-copy) (admin)
GET, DELETE /_rustybin/mocks/{name}/stateThe items of a stateful mock, or reset them (admin)
GET /_rustybin/mocks/{name}/coverageExample coverage of the draft and the live revision
GET /_rustybin/mocks/{name}/collections/{format}The mock as a collection
GET, PUT /_rustybin/mocks/{name}/operations/{op}One operation, or set its settings (admin)
GET /_rustybin/mocks/{name}/operations/{op}/sampleA valid request and response
POST /_rustybin/mocks/{name}/operations/{op}/validateValidate a body against the operation's schema
POST /_rustybin/mocks/{name}/operations/{op}/rules/testWhich rule would answer a request
GET, DELETE /_rustybin/mocks/{name}/requests, .../requests/{n}, .../requests/streamTraffic
GET /_rustybin/mocks/{name}/export, GET /_rustybin/mocks/exportrustybin.yaml export
POST /_rustybin/mocks/applyApply a rustybin.yaml document, ?prune=true (admin)
POST /_rustybin/mocks/reloadRe-read the configured files (admin)
GET /_rustybin/mocks/config.schema.jsonJSON Schema of rustybin.yaml

{op} is the operationId (or the id Rustybin made up, shown in the details and in X-Rustybin-Mock-Operation). The routes are also in /openapi.json under the Mocks tag and in the console's API explorer.

On every surface

The same job from the API, the console, the command line, an agent and the configuration document.

SurfaceWhere
API/_rustybin/mocks* (above); the mocks themselves at /mock/{name}/...
ConsoleMock APIs (/ui/#/mocks): the wizard, a mock's settings, security, operations, traffic, data, MCP server and deploy report (console)
CLIrustybin mocks ... for every route above (reference); rustybin mock validate, init, sample and check-config offline (CLI)
Management MCPlist_mocks, get_mock, preview_spec, get_mock_spec, get_mock_revision, create_mock, update_mock, set_operation, test_rules, check_mock, deploy_mock, rollback_mock, set_mock_enabled, duplicate_mock, delete_mock, sample_request, validate_payload, export_collection, get_mock_data, clear_mock_data, get_mock_traffic, clear_traffic, reload_mocks, try_request; the prompt mock_an_api (agent page)
rustybin.yamlmocks: (mocks as code), in a version 2 document with the rest of the instance (the whole instance as code)
EnvironmentRUSTYBIN_CONFIG_FILE, RUSTYBIN_MOCKS_DIR, RUSTYBIN_MOCKS_SAMPLE, RUSTYBIN_MOCKS_HOST, RUSTYBIN_MOCKS_STATE_DIR (configuration)