Skip to main content

Prism — OpenAPI Mock Server and Contract Validator

Prism by Stoplight is an open-source CLI tool that turns your OpenAPI spec into a real HTTP mock server in one command. It also operates as a validating proxy that checks whether your real API adheres to its OpenAPI contract — catching spec drift and schema violations before they reach production.

✓ Mock server from OpenAPI spec ✓ Request and response validation ✓ Proxy mode for real API validation ✓ Dynamic response generation ✓ Open source (Apache 2.0)

What is Prism?

Prism is maintained by Stoplight (the company behind Stoplight Studio, the API design platform). It is a Node.js CLI that reads an OpenAPI 2.x or 3.x specification file and provides two core capabilities: a mock server that generates HTTP responses from the spec, and a validating proxy that forwards requests to a real backend while checking that all traffic conforms to the spec.

The key difference from tools like Mockoon or Hoppscotch is that Prism is spec-driven. You do not manually define routes and responses — Prism derives everything from your OpenAPI spec. This makes it ideal for API-first workflows where the spec is the single source of truth. When the spec and the implementation disagree, Prism surfaces the violation immediately.

Key Features

Installation

# Install Prism CLI globally
npm install -g @stoplight/prism-cli

# Or run with npx (no install required)
npx @stoplight/prism-cli mock api.yaml

Mock Mode — Serve Responses from Your Spec

# Start a mock server from an OpenAPI 3.x spec
prism mock api.yaml

# Mock on a custom port
prism mock api.yaml --port 4010

# Mock with dynamic response generation (uses x-faker or spec examples)
prism mock api.yaml --dynamic

# Mock multiple specs at once
prism mock api.yaml users.yaml --port 4010

Proxy Mode — Validate a Real API

# Proxy mode: validate real API requests/responses against OpenAPI spec
prism proxy api.yaml https://api.example.com --port 4010

# Requests go through: client -> Prism (4010) -> real API -> Prism -> client
# Prism validates both request and response against your spec
# Violations are logged with detailed error messages

Minimal OpenAPI Spec Example

openapi: 3.0.3
info:
  title: Example API
  version: 1.0.0
paths:
  /users:
    get:
      summary: List users
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  required: [id, email]
                  properties:
                    id:
                      type: integer
                      example: 42
                    email:
                      type: string
                      format: email
                      example: [email protected]

With the spec above, running prism mock api.yaml immediately starts a server that returns the example values defined in the spec. A GET request to /users returns the example user array without any additional configuration.

Prism vs Mockoon vs MSW

Feature Prism Mockoon MSW
Spec-driven Yes (OpenAPI required) Optional import No
Contract validation Yes (built-in) No No
Proxy mode Yes Partial (record) No
Visual UI CLI only Desktop GUI Code only
Target user API-first teams Frontend devs JS frontend testing
Docker support Official image Official image Via Node.js

Use Cases

Frequently Asked Questions

What is the difference between Prism mock mode and proxy mode?▼

In mock mode, Prism generates HTTP responses directly from your OpenAPI spec — it uses the example values defined in the spec, or generates random values matching the schema when using --dynamic. No real backend is needed. In proxy mode, Prism sits between your API client and the real backend: it forwards requests to the real server and validates both the outgoing request and the incoming response against your OpenAPI spec. Any deviation (an undocumented field, a wrong status code, a type mismatch) is logged as a contract violation. Proxy mode is powerful for catching spec drift in existing APIs.

What is contract testing and why does Prism help?▼

Contract testing verifies that an API producer (the backend) and API consumers (frontend, mobile, other services) agree on the API contract — the routes, request schemas, response schemas, and status codes defined in an OpenAPI spec. Without contract testing, consumers discover breaking changes only when they deploy to staging or production. Prism enforces the contract by validating requests and responses against the OpenAPI spec at the HTTP layer. If the real API returns a field with the wrong type, or the client sends a request that violates the schema, Prism catches it immediately.

How does Prism compare to Mockoon?▼

Prism is spec-driven: it generates mock responses directly from an OpenAPI spec file, enforcing schema contracts automatically. Mockoon is a visual tool where you manually define routes and responses — great for quick prototyping but not tied to a spec by default. Prism requires an existing OpenAPI spec; Mockoon does not. Prism is better suited for API-first development workflows where the OpenAPI spec is the source of truth. Mockoon is better for teams that want a quick visual tool without a spec. Prism also has proxy mode for validating real APIs — Mockoon does not.

What does Prism do when a request fails validation?▼

By default, Prism returns a 422 Unprocessable Entity response when a request violates the OpenAPI spec — for example, when a required field is missing, a field type is wrong, or a route does not exist in the spec. This makes validation errors immediately visible to the API consumer. You can configure Prism to be more lenient with --errors=false to log violations without rejecting requests. In proxy mode, Prism passes the request through even if it is invalid but logs the contract violation with full details.

How does Prism compare to MSW (Mock Service Worker)?▼

MSW intercepts requests at the browser or Node.js level using Service Workers or Node.js HTTP interceptors — it is primarily used in frontend unit and integration tests (Jest, Vitest, Playwright). Prism runs as a real standalone HTTP server, making it usable from any HTTP client regardless of the test framework or language. Prism is spec-driven (OpenAPI), while MSW handlers are written in JavaScript. Prism is better for API contract validation and spec-driven development; MSW is better for JavaScript frontend testing where the mock server should be co-located with test code.

Can I use Prism with Stoplight Studio?▼

Yes, Stoplight Studio is a visual API design tool by the same company (Stoplight) that produces Prism. Stoplight Studio exports OpenAPI specs that Prism can consume immediately. The recommended workflow is: design the API in Stoplight Studio, use Prism to run a mock server from the exported spec during frontend development, and use Prism proxy mode to validate the real implementation when it is ready. This creates a fully API-first development loop from design through validation.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →