Turn any OpenAPI2/3 and Postman Collection file into an API server with mocking, transformations and validations.
Prism is a powerful tool designed to transform OpenAPI v2/v3 specifications and Postman Collections into fully functional API servers, complete with mocking, request validation, and content transformation capabilities. Whether you're developing, testing, or documenting APIs, Prism streamlines the process by enabling rapid prototyping and ensuring compliance with your API definitions.
Key Features:
Mock Servers: Quickly create lifelike mock servers based on your API specifications to simulate real-world behavior without backend infrastructure.
README
Prism Overview
Prism is a set of packages for API mocking and contract testing with OpenAPI v2 (formerly known as Swagger) and OpenAPI v3.x.
Prism provides:
Mock Servers: Life-like mock servers from any API specification document.
Validation Proxy: Contract Testing for API consumers and developers.
Comprehensive API Specification Support: OpenAPI v3.1, OpenAPI v3.0, OpenAPI v2.0 (formerly Swagger) and Postman Collections.
Ways to Use Prism
Hosted Prism
Stoplight provides hosted mock servers for convenience so that API consumers can experiment with an API without the need for backend code.
Use one of these options for instant, hosted mock servers:
Stoplight Platform: Collaborative API Design Platform for designing, developing and documenting APIs with hosted mocking powered by Prism.
Stoplight Studio: Free visual OpenAPI designer that comes integrated with mocking powered by Prism.
Prism is an open-source HTTP server run from the command-line. It provides mocking, request validation, and content negotiation. Use it standalone tool or in continuous integration.
Installation and Usage
This information refers to Open Source Prism 3.x, which is the current version most likely you will use. If you're looking for the 2.x version, look at the
Validation Proxy: Enforce contract testing by validating incoming requests against your OpenAPI spec, ensuring consistency between documentation and implementation.
Comprehensive API Support: Works seamlessly with OpenAPI v3.1, v3.0, v2.0 (Swagger), and Postman Collections, making it versatile for various use cases.
Content Negotiation & Transformation: Dynamically transform request and response payloads based on media types, supporting flexible integration scenarios.
Security Testing: Validate security schemes such as OAuth2, API keys, and more to ensure your API adheres to specified security requirements.
Audience & Benefits:
Ideal for API developers, testers, and teams focused on API design and integration. Prism accelerates development by enabling rapid prototyping, ensures compliance with OpenAPI specifications, and supports continuous integration/continuous deployment (CI/CD) workflows through automated testing. It also facilitates collaboration between teams by providing a shared environment to experiment with APIs before full implementation.
Prism is available as an open-source tool that can be installed via winget or used in hosted environments for convenience.
Prism can help you create a fake "mock" based off an OpenAPI document, which helps people see how your API will work before you even have it built. Run it locally with the prism mock command to run your API on a HTTP server you can interact with.
Prism can help you check for discrepencies between your API implementation and the OpenAPI document that describes, letting you funnel HTTP traffic through it with the prism proxy command.
Prism uses localhost by default, which usually means 127.0.0.1. When using docker the mock server will
be unreachable outside of the container unless you run the mock command with -h 0.0.0.0.
Why am I getting 404 errors when I include my basePath?
OpenAPI v2.0 had a concept called "basePath", which was essentially part of the HTTP path the stuff
after host name and protocol, and before query string. Unlike the paths in your paths object, this
basePath was applied to every single URL, so Prism v2.x used to do the same. In OpenAPI v3.0 they
merged the basePath concept in with the server.url, and Prism v3 has done the same.
We treat OAS2 host + basePath the same as OAS3 server.url, so we do not require them to go in
the URL. If you have a base path of api/v1 and your path is defined as hello, then a request to
http://localhost:4010/hello would work, but http://localhost:4010/api/v1/hello will fail. This
confuses some, but the other way was confusing to others. Check the default output of Prism CLI to
see what URLs you have available.