Platform

A mock API server built from your saved examples

A mock server lets front-end and mobile developers build against an API before it exists, and lets tests run without a fragile dependency. In Swastik Codes a mock server is generated from the examples saved in a collection: every example becomes a response the mock can return, at a public URL.

Get started freeSign inOpen the app

From examples to a running mock

Save responses as examples while you work, or write them by hand (status, headers and body), then create a mock server for the collection. Each mock gets its own URL of the form:

Text
https://swastik.codes/api/mock/<mock-id>/v1/orders/42

The part after the mock id is matched against the paths of your saved requests, including {{variables}} resolved from the collection and an optional environment you attach to the mock.

Request matching

When a call comes in, every example for that method and path is scored on how well its saved request matches the call's query parameters, headers and body, and the best one answers. You can make matching stricter:

  • match body: only examples whose saved request body equals the call's body (JSON compared structurally)
  • match headers: only examples whose listed request headers equal the call's

Both can be switched on for the whole mock or per call.

Choose a response from the client

Clients can steer the mock with request headers, which is ideal for testing error states in a UI:

HeaderEffect
x-mock-response-namereturn the example with this name
x-mock-response-codereturn an example with this status code
x-mock-response-idreturn a specific example by id
x-mock-match-request-bodyturn body matching on or off for this call
x-mock-match-request-headersturn header matching on, off, or for listed headers
x-mock-response-delaydelay this response (milliseconds, up to 30 seconds)
Shell
curl -H "x-mock-response-code: 404" \
  https://swastik.codes/api/mock/<mock-id>/v1/orders/999

Dynamic responses with templates

Example bodies and header values can echo parts of the incoming request, so one example covers many calls:

JSON
{
  "id": "{{$pathSegments '2'}}",
  "search": "{{$queryParams 'q' ''}}",
  "customer": "{{$body 'customer.name' 'anonymous'}}",
  "requestId": "{{$headers 'x-request-id' ''}}"
}

Missing values fall back to the default you provide.

Delays, privacy and the call log

Add a fixed delay (up to 30 seconds) to every response to see how your app handles a slow network. Mark a mock as private and callers must send the X-Api-Key of a user with access to the workspace. The call log keeps the last 100 calls with method, path, status, the example that answered and the time taken; Authorization, Cookie, X-Api-Key and Proxy-Authorization values are redacted. Mocks answer CORS preflights from any origin, so browser apps can call them directly. Request bodies sent to a mock are limited to 1 MiB.

Run a mock on your computer

swc mock collection.json --port 4010 serves the same mock from your machine, with no account: identical matching, the same x-mock-response-* headers and templates, open CORS for front ends on other ports, and a log line for every request. See Mock servers.

How it works

  1. Save examples on the requests in a collection in the app.
  2. Create a mock server for the collection, optionally with an environment and a delay.
  3. Point your app at the mock URL and use Try it to test calls from inside Swastik Codes.

Hosted mocks need a free account and a cloud workspace. You can also create local mocks that answer inside the app using the same matching rules.

Frequently asked questions

Is the mock server free?

Yes. Swastik Codes is free to use today, including mock servers.

Can I mock an API from an OpenAPI definition?

Yes. Generate a collection from your definition in API design or import it, add or edit examples, and create a mock from that collection.

How do I return an error response on demand?

Save an example with the error status, then call the mock with x-mock-response-code or x-mock-response-name set to choose it.

Does the mock keep state between calls?

No. Each call is answered from the saved examples and the request itself, which keeps mocks predictable.

Try it on your own API

Swastik Codes runs in the browser and is free to use. Create an account to send requests, sync your workspaces and invite your team.