WSO2Con2025 Logo

March 18-20 | Barcelona, Spaain

 
choreo
2024/11/11
 
11 Nov, 2024

Mocking Your APIs in Minutes with Choreo

  • Chathuranga Siriwardana
  • Associated Technical Lead - WSO2

Do you have an open API specification that needs to be transformed into a functional mock server? With Choreo’s latest release, you can now use Prism Mock service components to mock your open API specifications.

This is powered by Prism, an open source technology, allowing you to tap into Choreo’s robust functionalities, including API management, observability, DevOps, and more. Both internal and external consumers can access the Prism mock services through the internal marketplace and Developer Portal, just like any other service.

Why You Need Mock Services

The following use cases can be identified when API developers adopt an API-first approach.

1. Early Tryout and Feedback from Internal Teams

API developers often need feedback from internal teams as early as possible. By creating a mock service from the API specification, they can share it internally on the Choreo marketplace, allowing teams to test and provide feedback before the actual API is ready.

For instance, if Team A is developing an API and Team B relies on it for their service, Team A can share the mock service early. This quick feedback loop helps identify and resolve issues, improving the API before its final release.

2. Early Testing and Feedback from External Stakeholders

External stakeholders can also benefit from early access to APIs. API providers can expose a mock service using their API specifications. By publishing mock services in a pre-released state, API providers allow external developers to test integrations and provide feedback, ensuring the API meets their needs before the final release.

3. Sandbox Endpoints for Your APIs

Another important use case for mock services is providing a sandbox endpoint for your API. This sandbox endpoint enables external developers to explore the API’s functionality in a controlled environment without impacting live production data. API providers can add mock endpoints in their API sandbox endpoints and make it available on the developer portal.

Getting Started with Mocking

Prerequisites

  • A GitHub, BitBucket, or GitLab repository with a valid endpoint configurationa.
  • Optionally, Add x-faker keysa to the properties of the open API specification’s schemas. This allows consumers to receive dynamic content by including a specific header in their HTTP requests.

To publish a mock service, sign into the Choreo console and follow these steps.

  1. Create a new project or navigate to an existing one. Click the + Create button to create a Prism mock component.
  2. Select the Service card.
  3. Provide a name, and description (optional) for the mock service, and provide the version control repository details containing the open API specification to be mocked.
  4. Choose Prism Mock as the buildpack and select the project path where the .choreo directory resides.
  5. Click Create. The initial build will start automatically.

  6. Deploy the component using the Configure and Deploy button on the image card.
  7. The mock service will now be available in the internal marketplace.
  8. To make the mock service available on the Developer Portal, update the lifecycle status to either Pre-Released or Published. It is recommended to use the Pre-Released status to indicate to consumers that this is a mock service.

Consuming a mock service in Choreo follows the same process as any regular service. Prism Mock services deliver static content based on examples from the OpenAPI specification. If the API provider has included x-faker annotations, you can access dynamic, realistic content by adding the prefer: dynamic=true header to your HTTP requests.

Sign up and start using Choreo for free. Learn about Prism Mock components by following our documentation and connect with our Discord channel to ask questions.

English