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

Gateway recipes

Rustybin is designed to sit behind any API gateway, AI gateway, service mesh or load balancer. This page lists, per capability, what to configure in the gateway and what to look at in Rustybin to prove it worked. The first part is gateway-agnostic; a few vendor snippets follow at the end.

General setup, whatever the gateway:

  • Upstream: http://<rustybin>:80 (HTTP and WebSocket), https://<rustybin>:443 (TLS upstream, demo CA from /auth/mtls/get-ca-cert), <rustybin>:50051 (gRPC, h2c).
  • Set RUSTYBIN_TRUST_FORWARD=true when the gateway sends X-Forwarded-* or Forwarded, so /echo, /ip, the OIDC issuer, Agent Cards and MCP metadata describe the client-facing URL. Rustybin uses the rightmost non-private address of X-Forwarded-For, so place it behind proxies you control.
  • Tag demo traffic with X-Rustybin-Session (a header the gateway can add per consumer) and keep the web console's Live traffic view open: it shows every request exactly as the gateway forwarded it.
  • Use GET / for the gateway's own liveness probe of Rustybin, and /health only for failover demos.

HTTP API gateway capabilities

CapabilityConfigure in the gatewayPoint it atObserve
Routing, path rewritingA route with a prefix strip or rewrite/anythingpath, url in the echo
Request transformationAdd, remove or rename headers, query parameters, body fields/echoheaders, query_params, body in the echo
Response transformationAdd or remove response headers, rewrite the body/response-headers?..., /echoThe response the client receives
Rate limitingA limit per consumer or IP/echo429 and the gateway's rate-limit headers; the console's load generator draws the histogram
Key authenticationKey auth, then strip or forward the key/anythingWhether the key header reached the upstream
Credential injectionThe gateway adds apikey: my-key or Basic credentials/auth/api-key, /auth/basic-auth200 only when the gateway injected them
JWT validationJWKS from /oauth/jwks (RS256) or the HS256 demo secret/auth/jwt/decodeThe forwarded token's claims; /auth/jwt re-validates
OIDC / OAuth 2.0Issuer http://<rustybin> (discovery), client rustybin / secret, users demo / demoany routeThe Authorization header or identity headers in /echo; introspection at /oauth/introspect
HMAC signingThe gateway signs requests to the upstream/auth/hmac200, plus the signing string the server computed
mTLS to the upstreamClient certificate from /auth/mtls/get-client-cert, trust /auth/mtls/get-ca-certhttps://<rustybin>:443/auth/mtlsauth_type: mtls, source: tls
mTLS terminationTerminate client mTLS, forward the certificate in a header/auth/mtls with RUSTYBIN_MTLS_IN_HEADERsource: header, the client's subject
CachingProxy cache honouring Cache-Control/cache/60The gateway's cache status header; Rustybin's inspector shows only the first request
RetriesRetry on 5xx/flaky/recover/2 or X-Rustybin-Fail: 503:50The client gets 200; the inspector shows the retried attempts
Circuit breakingOutlier detection / breaker/flaky/after/5The gateway stops calling after the failures
TimeoutsUpstream timeout of a few seconds/delay/5s or X-Rustybin-DelayThe gateway's 504
Load balancing, failoverSeveral Rustybin instances with different RUSTYBIN_INSTANCE_ID, active health checks on /health/identityinstance_id distribution; POST /health/unhealthy takes one out
CORSThe gateway's CORS policy, with RUSTYBIN_CORS_ORIGINS=offany routeOnly the gateway's Access-Control-* headers
Request size limitsA body size limit below Rustybin's 1 MiBPOST /echoThe gateway's 413
IP restrictionAllow or deny lists/ipThe client IP the gateway forwarded
Webhook validationSignature verification plugin with the demo secretsign with /webhooks/sign, deliver to /webhooks/receive/demo204 vs 401
HTTP logging, mirroringLog or mirror to an HTTP endpointa request bin URLThe captured log entries
WebSocketWebSocket proxying/ws, /ws/timeEchoed frames, subprotocol pass-through
gRPC, gRPC-Webh2c upstream; gRPC-Web translationEchoService on :50051metadata in the reply; Fail for status mapping
GraphQLQuery depth / cost limits, persisted queries/graphql400 from the gateway before Rustybin's own limits
SOAP / XMLSOAP routing, XML to JSON/soap, /soap?wsdlThe SOAP response and faults
Request chainingOrchestrate steps 1 to 4/orchestration/step/*A completed transaction only when every header was passed on

AI gateway capabilities

CapabilityConfigure in the gatewayPoint it atObserve
AI proxy, provider abstractionUpstream provider URLs from Providers/ai/<provider>/...X-Rustybin-Provider, native responses
Credential injectionThe provider key from the gateway's vaultany provider, with X-Rustybin-Require-Auth: trueX-Rustybin-Credential: bearer ****abcd
Token rate limitingTokens per minute per consumerchat completionsDeterministic usage counts; the gateway's 429
Prompt decoration / templatesSystem prompt or template pluginsmodel rustybin-echoThe reply is the decorated prompt
Prompt guardDeny patterns, or an external guardrail service at /guardrails/*any chat endpointThe gateway blocks before Rustybin is called (inspector stays empty)
Response sanitisingPII or secret redaction on responsesmodel rustybin-scripted, prompt customer record or secretsRedacted SSN, card, keys in the client response
Semantic cacheEmbeddings model at /ai/openai/v1/embeddingschat completionsSimilar prompts served from cache
Fallback, retriesFallback to a second provider or instanceX-Rustybin-Fail: 429 or ?fail=overloadedThe fallback target answers; X-Rustybin-Instance
StreamingSSE pass-through, buffering offstream: true with X-Rustybin-Tokens-Per-SecondTokens arrive at the configured pace
ObservabilityLogging, metrics, tracinganyX-Rustybin-Request-Id and /ai/requests/{id}
MCP gatewayRoute on Mcp-Method / Mcp-Name, OAuth for /mcp/protected, tool filtering, server aggregation/mcp, /mcp/servers/*inspect_request shows injected identity headers
Agent (A2A) gatewayRoute per agent, authenticate, rewrite Agent Card URLs/a2a/*, /.well-known/agent-card.jsonCard URLs pointing at the gateway (with RUSTYBIN_TRUST_FORWARD)

Vendor examples

The snippets below are illustrative examples, not executed in CI. They show how the generic patterns map onto a few well-known gateways; check them against your gateway version's documentation. Rustybin itself stays vendor neutral.

Kong (declarative configuration)

Route /demo to Rustybin with key authentication and a rate limit, then look at /demo/anything in the Live traffic view:

_format_version: "3.0"
services:
  - name: rustybin
    url: http://rustybin:80
    routes:
      - name: rustybin-demo
        paths: ["/demo"]
        strip_path: true
    plugins:
      - name: key-auth
      - name: rate-limiting
        config:
          minute: 5
          policy: local
consumers:
  - username: alice
    keyauth_credentials:
      - key: alice-key

Envoy (static configuration)

A listener on port 10000 forwarding to Rustybin with a 2 second timeout and retries on 5xx; try it with /flaky/recover/2 and /delay/5s:

static_resources:
  listeners:
    - name: listener_0
      address:
        socket_address: { address: 0.0.0.0, port_value: 10000 }
      filter_chains:
        - filters:
            - name: envoy.filters.network.http_connection_manager
              typed_config:
                "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
                stat_prefix: ingress_http
                route_config:
                  virtual_hosts:
                    - name: rustybin
                      domains: ["*"]
                      routes:
                        - match: { prefix: "/" }
                          route:
                            cluster: rustybin
                            timeout: 2s
                            retry_policy:
                              retry_on: 5xx
                              num_retries: 3
                http_filters:
                  - name: envoy.filters.http.router
                    typed_config:
                      "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
  clusters:
    - name: rustybin
      type: STRICT_DNS
      load_assignment:
        cluster_name: rustybin
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address: { address: rustybin, port_value: 80 }

Apache APISIX (Admin API)

A route for /echo with round robin over two Rustybin instances (use /identity to see the distribution):

curl http://127.0.0.1:9180/apisix/admin/routes/rustybin -X PUT \
  -H "X-API-KEY: $APISIX_ADMIN_KEY" \
  -d '{
    "uris": ["/echo", "/identity"],
    "upstream": {
      "type": "roundrobin",
      "nodes": { "rustybin-01:80": 1, "rustybin-02:80": 1 }
    }
  }'

Tyk, KrakenD and other gateways follow the same patterns; no snippets are given for them here.