Prism
When
An API mock server with Prism is best suited when the API is NOT being developed concurrently with the client applications. Prism is a best-in-class Mock Server and Validation Proxy for OpenAPI documents and Postman Collections. It 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.
Prerequisites
- OpenAPI to create API documentation.
- A host server to deploy the API mock server. Find detailed instructions for several hosting providers.
Instructions
Developers can use the api-mock-templates or web templates (e.g., rails-templates, elixir-templates, gin-templates) directly to create an API mock server or follow the steps below to create one from scratch:
- Create an OpenAPI specification file or generate one from Postman Collection.
- Create an API Mock Server with Prism.
- Deploy the mock server to a host server.
- Set up the Continuous Deployment with GitHub Actions.
Prism Usages
After setting up the mock server, the client side can call all APIs as usual with the mock server base URL.
One of Prism’s features is supporting different responses with an API:
-
With defined response examples, developers can call the API with the
Prefer
headerexample=name-of-example
to get the expected response. -
Dynamic response by specifying the
Prefer
header with thedynamic
key set totrue
.
For instance, with the Nimble Survey API project, developers can call the API with:
-
The
Prefer
headerexample=bangkok
to get the response with thebangkok
example: -
The
Prefer
headerexample=riverside
to get the response with theriverside
example: -
The
Prefer
headerdynamic=true
to get the dynamic response: