Stateful API flows

Mock APIs that actually have state

Real APIs don't return the same response every time. Mockra's stateful sequences let you define ordered steps — so your mock behaves like the real thing across sequential calls.

Start for freeSee Starter plan
The problem
  • ✕Static mocks always return the same response — real APIs don't
  • ✕Can't test an OAuth flow where the token expires after one use
  • ✕Can't simulate a payment that succeeds then fails on retry
  • ✕Can't test inventory depletion across sequential purchase calls
  • ✕Multi-step flows require real API sandboxes that are slow and unreliable
With Mockra
  • ✓Define ordered steps: each call advances the sequence automatically
  • ✓Set repeat counts per step — serve a response N times before advancing
  • ✓Terminal steps are sticky — once reached, they repeat forever
  • ✓State is tracked atomically per endpoint and per namespace
  • ✓Reset state between test runs with a single API call or dashboard button

Example stateful sequences

OAuth token flow
POST /auth/token
1
200Token issued
repeat: 1
2
401Token expired
repeat: 3
3
200Refresh succeeds
sticky
Payment processing
POST /payments
1
200Payment pending
repeat: 1
2
200Payment processing
repeat: 2
3
200Payment confirmed
sticky
Inventory depletion
GET /products/SKU-001
1
200In stock: 5 units
repeat: 3
2
200Low stock: 1 unit
repeat: 2
3
404Out of stock
sticky

Configure a sequence via API

curl — configure stateful sequence
# Define a payment flow that progresses across calls
curl -X PUT https://api.mockra.io/mock-configs/:id/state \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "state_sequence": [
      {
        "status_code": 200,
        "body": { "status": "pending", "id": "pay_123" },
        "repeat": 1
      },
      {
        "status_code": 200,
        "body": { "status": "processing", "id": "pay_123" },
        "repeat": 2
      },
      {
        "status_code": 200,
        "body": { "status": "succeeded", "id": "pay_123" },
        "sticky": true
      }
    ]
  }'

# Reset state between test runs
curl -X POST https://api.mockra.io/mock-configs/:id/reset-state \
  -H "Authorization: Bearer <token>"
Common stateful patterns
OAuth flowsPayment sequencesInventory depletionRate limit simulationToken refresh cyclesRetry logic testingWebhook delivery statesAsync job polling

Stateful mock sequences are available on the Starter plan and above.

Test the flows that matter most

Define sequences, test multi-step flows, reset state between runs.

Get started for free