HomeAPI Mocking › Turn an OpenAPI Spec into a Live Mock with Prism

Turn an OpenAPI Spec into a Live Mock with Prism

One command from contract to running mock

Prerequisites

Steps

1

Run Prism

Point Prism at your spec.

bash
npx prism mock openapi.yaml
2

Call an operation

Request any path in the spec; Prism returns example values.

bash
curl localhost:4010/users

Verify

Every operation in your spec now has a live, example-backed response — the mock can never drift from the contract.

Because Prism reads the same OpenAPI file your docs and clients use, the mock and the contract are one source of truth.

Why this matters: frontend and backend usually diverge because the mock is modeled separately from the spec. With Prism that can’t happen — change the operation in the YAML and the mock changes with it, so the double always reflects what the API is supposed to do.

Troubleshooting tip: if Prism returns a 404 for a path you expect, the path is likely missing or named differently in your spec — Prism only serves what the OpenAPI document actually declares, so validate the spec before blaming the tool.

What you’ll have when you finish

You’ll have a Prism server mocking every operation in your OpenAPI file, each returning example-backed responses on a local port. Because the mock reads the same spec your docs and clients use, it can never drift from the contract.

The double is live the moment Prism boots, so a frontend developer can build against it with no meeting and no backend dependency — a true spec-first workflow.

Expected output

Calling any path in the spec returns the example value you defined, with a 200 for valid operations and a 400 when the request violates the schema. Prism validates incoming requests, so a malformed call fails fast and locally instead of against the real service.

Operations without example values return thinner default data, which is Prism’s way of telling you the spec needs filling in. Treat that as a prompt to enrich the spec, not a tool bug.

Troubleshooting

If Prism returns 404 for a path you expect, the path is likely missing or named differently in your spec. Prism only serves what the OpenAPI document declares, so validate the spec before blaming the tool.

If validation rejects a request you think is valid, check the schema’s required fields and types. A missing required property or a wrong type triggers the 400; align the request or fix the spec.

If the mock returns empty bodies, your operations lack example values. Add `example` per response and re-run; the payloads will follow.