Skip to content

Mocking API Responses

When your backend isn’t ready—or you want to simulate specific responses—Inspectr lets you mock APIs based on an OpenAPI specification and override responses in real time.

Inspectr Mocking

Inspectr leverages Stoplight Prism behind the scenes, giving you access to both static and dynamic mocking powered by Faker and JSON Schema Faker.

Want a fast demo? Jump to the Mocking Quick Start →.


  • Frontend development before backend is available
  • Testing edge cases (timeouts, errors, unexpected payloads)
  • Demos and offline API development
  • Simulating invalid or large payloads for robustness testing

You can provide the OpenAPI documents as a local file or as a public URL by using the --mock-backend parameter.

Local File:

Terminal window
inspectr --listen=:8080 --mock-backend=./openapi.yaml

Public URL:

Terminal window
inspectr --listen=:8080 --mock-backend=https://inspectr.dev/demo/hello.openapi.yaml

You can also launch an OpenAPI Mock using Inspectr, by just using the URL https://inspectr.dev/launch with a reference to any remote OpenAPI document:

https://inspectr.dev/launch?openapi=https://inspectr.dev/demo/hello.openapi.yaml

Replace the openapi parameter with the URL of your own OpenAPI file. Inspectr will start immediately with mocking enabled.

Launch OpenAPI mock Inspectr Launch OpenAPI mock

You can easily mock the typical OpenAPI example APIs using Inspectr, by clicking the launch link:


Static mocking uses predefined examples in your OpenAPI spec to return consistent, predictable responses.

paths:
/items:
get:
responses:
'200':
description: Success
content:
application/json:
examples:
default:
value:
items: ["A", "B", "C"]

Save it as openapi.yaml.

Step 2: Start Inspectr in Static Mock Mode

Section titled “Step 2: Start Inspectr in Static Mock Mode”
Terminal window
inspectr --listen=:8080 --mock-backend=./openapi.yaml
  • Returns mock responses based on OpenAPI examples
  • No backend service needed
  • Captures requests in the Inspectr UI at http://localhost:4004

Use headers to simulate conditions or return different examples:

HeaderDescription
inspectr-response-statusOverride status code (e.g. 404, 500)
inspectr-response-delayAdd artificial delay in milliseconds
inspectr-response-exampleChoose a specific OpenAPI example by name
inspectr-response-content-typeOverride Content-Type header
Terminal window
curl http://localhost:8080/items \
-H "inspectr-response-status: 404"

See the guide Response Overrides → for more examples


Dynamic mocking generates data using Faker and JSON Schema Faker based on your OpenAPI schema and x-faker extensions.

components:
schemas:
Pet:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
x-faker: name.firstName
photoUrls:
type: array
items:
type: string
x-faker: image.imageUrl

If x-faker is missing or invalid, Prism falls back to JSON Schema Faker.

Terminal window
inspectr --mock-backend=./openapi.yaml --mock-dynamic=true
{
"id": 12608726,
"name": "Addison",
"photoUrls": [
"http://lorempixel.com/640/480",
"http://lorempixel.com/640/480"
]
}

ModeBehavior
StaticReturns predefined examples from OpenAPI spec
DynamicGenerates data using Faker/JSF from schema and x-faker annotations

Use static mode for stable mocks based on the provided examples. Use dynamic mode to simulate variability and more dynamic data.


Mock mode in Inspectr gives you full flexibility when developing against APIs. Whether you need consistent fixtures or random data, mocking accelerates frontend and QA workflows.