Test requests in the reference
The Scalar reference sends live requests. Sandbox gateway leads the server list, and calls sent there cross a real network. A shell can run the same calls. Select Browser demo instead and the answer comes back inside the page, with no account and no local process.
How the browser demo works
The published contract lists three targets. One of them, /software/api-mock, resolves to the page you are already on. A request handler in the reference page answers calls to that path from response bodies generated from the contract's own schema examples.
That design solves three problems at once:
- No mixed content block. A page loaded over HTTPS can't call
http://localhost. Answering same-origin avoids the request that browsers refuse. - No CORS preflight. The response never crosses an origin, so there is nothing to allow.
- No server to keep alive. GitHub Pages serves static files, and a static host can't run a mock server. The handler runs in the visitor's browser.
Each body is generated from the schema examples. Field names, enums, the microchip pattern, and the RFC 9457 shapes all match the specification. Selecting production or sandbox targets a real host instead.
Send your first request
- Open the interactive API reference.
- Confirm the server dropdown reads Sandbox gateway. That route needs no credential.
- Expand
GET /animals/{animalId}, enterpet_krypto_210as the path value, and select Send.
The response returns Krypto's record with microchip 985141002348123, rabies tag RB-2026-9921, and the AVAILABLE status.
Which routes need a credential
The adoption catalog and the route that accepts test webhook dispatches stay public. A prospective adopter browses the catalog before creating an account, and a receiver test needs no credential. The remaining routes carry a security requirement:
| Route | Requirement |
|---|---|
GET /animals | None. Public catalog. |
GET /animals/{animalId} | None. Public animal profile. |
POST /applicants | None. Registration starts an account. |
POST /sessions | None. Sign-in produces the token. |
POST /webhooks/test-dispatch | None. A receiver test needs no credential. |
| Everything else | OAuth 2.0 bearer token, or X-API-Key on the routes that accept a key. |
The Browser demo ignores these requirements, so every route answers without a credential. The sandbox gateway verifies them, so a request can fail there while the same request succeeds in the demo.
Authenticate a request
The contract declares a real authorization server, so the bludhaven_oauth entry renders a Connect button rather than a paste field. Press Connect and the panel walks the consent screen on the sandbox gateway.
| Console entry | Action | Header |
|---|---|---|
bludhaven_oauth | Connect, approve, then send | Authorization: Bearer <token> |
api_key | Paste bpk_sandbox_pos_7f3a91c4 | X-API-Key: <key> |
The register key covers retail routes. For an animal write, paste bpk_sandbox_ops_2d8be05f instead. The authentication guide lists what each published key reaches.
A shell skips the panel and sends the header directly:
curl https://sandbox.bludhaven-pets.workers.dev/retail/inventory \
-H "X-API-Key: bpk_sandbox_pos_7f3a91c4"
A secured route without its header returns 401 Unauthorized with a ProblemDetails body and a WWW-Authenticate challenge. A made-up key fails the same way, because the gateway looks the value up in its registry.
Flows worth running
Read an animal record
Send GET /animals/pet_krypto_210. The response returns the Animal schema with a nested health record and the $150 placement fee. Replace the path value with pet_krypto_999 and the handler still answers, because it matches the route template rather than a stored record.
Attempt a conflicting hold
Send POST /adoptions/holds with animal_id set to pet_krypto_210 and any applicant_id. The first call returns 201 Created with a fresh hold id, a 30-minute expires_at, and a seconds_remaining countdown. Send it again with the same animal_id and the handler returns 409 Conflict with a ProblemDetails body naming the hold that blocked you.
Copy the hold id from the first response and send GET /adoptions/holds/{holdId} to read the countdown, or DELETE /adoptions/holds/{holdId} to release the animal. A release clears the lock, so the next hold attempt succeeds. The lock lives for the page session and resets on reload.
This flow shows a client how to read type, title, and detail from a conflict, then offer the adopter a waitlist instead of a failure.
Record a refund
Send POST /refunds with application_id set to app_2026_1188, amount_cents to 10000, and reason to CANCELLATION_AFTER_48H. The handler returns the placement fee and the supplies line split apart in breakdown, then names the deposit and license fee it withheld. A reconciliation job reads exactly that shape.
Request an operation the contract doesn't declare
Send GET /animals/pet_krypto_210/notes. No operation matches that path, so the handler returns 404 with a ProblemDetails body. That response exercises the error branch a client needs.
Call the sandbox gateway
The Sandbox gateway serves the same bodies over real HTTP. A shell reaches every operation without a browser.
curl https://sandbox.bludhaven-pets.workers.dev/animals/pet_krypto_210
A secured route needs a token this gateway signed, or a key it recognizes. The key path takes one header and no exchange:
curl https://sandbox.bludhaven-pets.workers.dev/retail/inventory \
-H "X-API-Key: bpk_sandbox_pos_7f3a91c4"
The token path starts with a mint:
curl -X POST https://sandbox.bludhaven-pets.workers.dev/oauth/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=bludhaven-staff-portal" \
-d "scope=write:animals"
Copy the access_token from the response into the next call:
curl -X POST https://sandbox.bludhaven-pets.workers.dev/animals \
-H "Authorization: Bearer <ACCESS_TOKEN>" \
-H "Content-Type: application/json" \
-d '{"name": "Orion", "species": "dog", "microchip_id": "985141002348999", "intake_branch_id": "loc_harbor_04"}'
Drop that header and the same call returns 401 with a ProblemDetails body and a WWW-Authenticate challenge. Send a made-up value of either kind and the gateway answers the same way, because it verifies a signature or looks a key up. Send a real credential that lacks write:animals and the call returns 403 with insufficient_scope in the challenge.
The authentication guide covers the consent screen, both grants, the two published keys, and the ten scopes.
Holds behave as they do in the console. Send POST /adoptions/holds twice with one animal_id and the second call returns 409 naming the live hold. Copy the id, then read the countdown with GET /adoptions/holds/{holdId} or release the animal with DELETE /adoptions/holds/{holdId}.
GET /health reports the contract the gateway loaded, the operation count, the live hold count, the OAuth endpoints, and how many keys it publishes. Run it after a deploy to confirm the gateway reached the network.
Test direct-to-storage presigned upload
Generate a signed upload URL, then stream binary bytes straight to storage without passing files through the application API:
# 1. Request presigned upload URL (needs write:animals scope)
curl -X POST https://sandbox.bludhaven-pets.workers.dev/animals/pet_krypto_210/photos \
-H "Authorization: Bearer <ACCESS_TOKEN>" \
-H "Content-Type: application/json" \
-d '{"content_type": "image/jpeg", "caption": "Krypto in harbor yard"}'
The response includes upload_url, which carries an HMAC signature and expiry. Use standard HTTP PUT to stream bytes directly:
# 2. PUT binary file directly to storage endpoint
curl -X PUT "<UPLOAD_URL>" \
-H "Content-Type: image/jpeg" \
--data-binary "@photo.jpg"
A tampered or expired signature returns 403. Successful upload returns 200 with the verified SHA-256 checksum and public CDN URL.
Test simulated webhook dispatch
Dispatch a signed webhook event to verify your HMAC receiver locally:
curl -X POST https://sandbox.bludhaven-pets.workers.dev/webhooks/test-dispatch \
-H "Content-Type: application/json" \
-o webhook-dispatch.json
The gateway signs its full example payload and writes the response to webhook-dispatch.json. Verify it with node scripts/verify-webhook.mjs webhook-dispatch.json. The webhooks guide covers the signing scheme in Node.js and Python.
The reference console lists the call under Webhooks as well. Send it against Browser demo and the header in the response verifies, because the demo signs at request time.
The gateway runs on short-lived edge isolates. A recycled isolate loses the holds it created, so a hold id can return 404 a moment after it worked. Place a fresh hold rather than reading the 404 as a released animal.
What each target can do
| Capability | Browser demo | Sandbox gateway | Production |
|---|---|---|---|
| Works on the deployed HTTPS site | Yes | Yes | Yes, with credentials |
| Returns contract-accurate bodies | Yes | Yes | Yes |
| Enforces the adoption state machine | Holds, reads, and releases | Holds, reads, and releases | Yes |
| Applies the 30-minute hold TTL | Countdown only, no reaper | Countdown, no reaper, may reset | Yes |
| Persists records between requests | Holds only, until reload | Holds only, until an isolate resets | Yes |
| Requires a credential | No | Yes, on secured routes | Yes |
| Verifies the token signature and scope | No | Yes | Yes |
No target validates a request body against the schema. The contract describes the shape, and the gateway answers from it.
Related guides
- Interactive API reference - the console that sends these requests.
- Domain model - the state machine that neither the demo nor the sandbox enforces.
- Adoption holds and concurrency - the conflict rules behind the
409example.