Save API responses as examples for docs and mocks

The response you just got is the best documentation the endpoint will ever have: real fields, real types, real error format. Usually it disappears when you send the next request. Save as example keeps it on the request.

Save one

  1. Send the request.
  2. Press Save as example above the response.
  3. Give it a name.

The example keeps the status, headers and body of that response. Open the request's Docs tab to see it under Example responses, make it the default, or delete it.

Which examples to keep

One example per thing a client has to handle:

NameWhy
200 OKThe normal shape, with every field filled in
200 OK, empty listClients must handle []
400 validation errorShows your error format
401 unauthorizedWhat an expired token looks like
404 not foundSo clients don't guess
409 conflict or 422The business errors this endpoint has

Error examples are the ones teams skip and clients need most. Getting them is easy: break the request on purpose (a bad id, a missing field, no token), send, save.

Clean them up first

A saved example is shown to whoever reads the docs and returned by mocks. Before saving:

  • Replace real customer data with obvious test data, or send against a test account.
  • Check headers for anything that shouldn't be shared: cookies, internal hostnames, debug headers.
  • Trim very long lists to a few items. An example shows the shape, not the whole table.

Examples from imports

You may already have examples. Response examples in a Postman collection (response[]) and in an OpenAPI file become saved examples when you import it. See mocking an API from its OpenAPI spec.

Mock servers

A mock server answers each call with a saved example of the matching request. It picks the default example, then the first 2xx one, unless the caller asks for another:

Terminal
curl -H 'x-mock-response-name: 404 not found' https://mock.requestarium.com/m_8f3k2x9q1z/users/42
curl -H 'x-mock-response-code: 422' https://mock.requestarium.com/m_8f3k2x9q1z/users

That's why the names matter: a frontend test asks for an example by name. See testing error states with mock servers.

Keep them current

Examples are snapshots. When an endpoint changes, its examples go stale, and mocks keep returning the old shape. Two habits help:

  • Resave the 200 OK example in the same pull request that changes the response.
  • Put a JSON Schema assertion on the request (see assertions with JSON Schema). When the real response changes, the test fails, which reminds you the example needs a refresh too.