Skip to Content
Mock ServerQuick start

Quick start

This guide publishes a spec-based mock server from an OpenAPI document and calls it. It works on every plan. You need an API repository with an OpenAPI file; every new repository includes an example at example/petstore.json.

Open the publish dialog

Open your repository, click Publish, and choose Publish MockServer.

Choose the documents

Spec-based is already selected. Under Documents & Base Paths, check the document to serve. Its base path is filled in from the document’s first servers URL, and you can change it. The Endpoint Preview column shows the resulting URL.

Publish dialog of a spec-based mock server

Deploy

Click Start deploy. The mock server is live as soon as the dialog closes, and its URL is on its page and in the repository’s Publish Center.

Call it

The examples below use a mock named petstore-sandbox with the Petstore example under /api/v3. Replace them with your own.

curl https://petstore-sandbox.mockserver.apigit.com/api/v3/pet/1 \ -H 'api_key: anything'
{"id":10,"name":"doggie","category":{"id":1,"name":"Dogs"},"photoUrls":["string"],"tags":[{"id":0,"name":"string"}],"status":"available"}

The body comes from the document. Petstore declares an api_key scheme for this operation, so the mock asks for that header. The value is not checked, only its presence.

Ask for another response

Use the Prefer header to choose a declared status or get randomized data:

# the 404 the operation declares curl -i https://petstore-sandbox.mockserver.apigit.com/api/v3/pet/1 \ -H 'api_key: anything' -H 'Prefer: code=404' # realistic random values instead of the stable sample curl https://petstore-sandbox.mockserver.apigit.com/api/v3/pet/1 \ -H 'api_key: anything' -H 'Prefer: dynamic=true'

See what the mock received

Open the mock server from the Publish Center and choose Logs to see each request and response.

Sending a request that does not match the document gets a clear error instead of a misleading success. Try /api/v3/pet/abc with the same header: petId is declared as an integer, so the answer is a 422 naming the parameter. See Error responses.

Next steps

Last updated on