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.
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
- Mock mode — starts a real HTTP server serving responses from OpenAPI examples or dynamically generated data
- Proxy mode — sits in front of a real API and validates every request and response against the spec
- Request validation — validates method, path, query parameters, headers, and request body against the spec
- Response validation — checks that the real API response matches the declared schema, status code, and content type
- Dynamic generation — with
--dynamic, Prism generates random but schema-valid response data using Faker - OpenAPI 2.x and 3.x — supports both Swagger 2.0 and OpenAPI 3.0/3.1 specifications
- Multiple specs — merge multiple OpenAPI files into a single mock server
- Content negotiation — respects Accept headers and returns the appropriate response format
- Verbose logging — detailed logs of every request, response, and validation error
- Docker image — official stoplight/prism Docker image for containerized environments
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
- API-first development: design the OpenAPI spec first, then let Prism serve a mock for parallel frontend and backend work
- Contract testing: use Prism proxy mode to verify that the real backend matches the agreed spec
- CI/CD validation: run Prism proxy in front of staging API and fail the build when spec violations are detected
- Consumer-driven contract checks: validate that third-party API responses match the schema you depend on
- Catching breaking changes: compare spec versions and use proxy mode to detect regressions in production APIs
- Generating realistic test data from OpenAPI schemas with the
--dynamicflag
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.
Related Products
on GumroadDevToolkit Starter Kit
A ready-to-deploy developer tools website with 12 built-in tools. Astro + Preact + Tailwind. Deploy to Cloudflare Pages for free. Built-in SEO, dark mode, and ad-ready layout.
Buy on Gumroad →TypeScript Quick Reference Toolkit
5 practical reference files for TypeScript developers: cheatsheet, TS vs JS comparison, 20 utility types with real examples, tsconfig best practices template, and 15 common mistakes guide. Print it. Keep it on your desk.
Buy on Gumroad →Developer Productivity Bundle
Stop rebuilding the same setup every project. 51 VSCode snippets, 40 Git aliases, 5 Docker Compose stacks, 5 GitHub Actions workflows, 5 README templates, and a dotfiles kit. Set up a professional dev environment in under an hour.
Buy on Gumroad →You Might Also Need
OpenAPI Validator
Paste your OpenAPI 3.x spec (YAML or JSON) to validate structure, find missing required fields, detect duplicate paths, check for missing operationIds, and get errors and warnings with path references.
Open free tool →
API Response Mock Generator
Generate realistic mock API responses with custom status codes, headers, and JSON body. Quick templates for 200, 401, 404, 429, 500 and more. Runs in your browser.
Open free tool →
OpenAPI Mock Generator
Paste an OpenAPI spec and get mock response data for testing. Generates realistic sample JSON from your API schema definitions.
Open free tool →
More Free Tools
Related Articles
MSW 2.0: The Best Way to Mock APIs in Frontend Tests
A complete guide to Mock Service Worker (MSW) 2.0 — setup, request handlers, Vitest and Jest integration, Storybook mocking, and best practices for realistic API mocking in frontend tests.
How to Use curl for API Testing
Master curl for API testing: GET, POST, auth tokens, JSON payloads, debugging flags, and practical real-world examples every backend developer needs daily.
curl 深度使用手冊:API 測試從入門到進階
curl 是每位開發者必備的 CLI 工具。本文涵蓋 GET/POST/PUT/DELETE 請求、認證、header 設定、檔案上傳、除錯技巧,以及 REST API 測試的完整實戰範例。
API Testing Best Practices 2026: Postman vs Insomnia vs Bruno
Complete guide to API testing in 2026. Compare Postman, Insomnia, and Bruno, learn best practices for REST and GraphQL testing, and build automation pipelines that catch regressions before production.
GraphQL Federation vs REST Microservices: Which Architecture in 2026?
Compare GraphQL Federation vs REST microservices — Apollo Federation, schema stitching, performance, team scaling, migration paths, and when to choose each in 2026.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$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.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →