choreo
2023/02/15
 
15 Feb, 2023 | 3 min read

Introducing the Choreo API Sandbox

  • Ruwini Wijesiri
  • - WSO2

Photo by Markus Spiske on Unsplash

Introduction

APIs are the core of any application. Consequently, it’s important to test how well the application works with these APIs. With the introduction of API sandbox support, Choreo provides developers a safe zone to test their applications.

What is an API Sandbox?

Let’s look at a real-world example to get a better understanding of this concept. 

Assume there is a payment API, and you need to develop an application to handle online payments. If you were to use the payment API during application development, you would be working with real money, and any failures during development would lead to monetary losses. It would also be difficult to reproduce edge case scenarios such as having insufficient funds for payment or transaction failures to assess how the application would behave in such scenarios. Wouldn’t it be great to do all this without using real money? 

That’s where the API sandbox comes into play. This mirrors the production environment, and has the same functionality as the actual production environment. However, an API sandbox only works with synthetic data, whereas the production environment works with real data. Therefore, an API sandbox provides developers an environment to test their application by simulating the production environment and enabling them to test and evaluate how the application will perform in production use cases.

Now, let’s see how we can create and use an API sandbox in Choreo.

How Can We Use an API Sandbox?

Choreo supports using an API sandbox for three types of components: REST APIs, GraphQL APIs, and API proxies. Each deployment environment in Choreo has its own corresponding sandbox. 

When deploying an API to an environment, developers can provide a sandbox endpoint. If an endpoint is configured, Choreo will generate two API URLs. One will be the primary API URL corresponding to the primary endpoint, and the other will be the sandbox API URL corresponding to the sandbox endpoint. This is illustrated in Figure 1 below.

Figure 1: Production and sandbox endpoints

How to create an API Sandbox for a REST API

1. Open the Choreo Console and create a sample REST API named ‘Payments’.

2. Go to the Deploy page.

3. Click on Configure & Deploy in the build area. Configure a Sandbox endpoint and deploy it. Choreo will provision two endpoints for the API on the Dev environment. If you go to the Test page, you will see two URLs instead of one.

4. When promoting the build to Production, developers can provide a sandbox endpoint for the production environment. Choreo will provision two URLs, just like in step 3. 

Figure 2: Configure sandbox endpoint

5. Go to the Lifecycle tab on the Manage page and publish the API to make it available to consumers.

API sandboxes can be used for GraphQL and API proxies as well.

Test the API Sandbox

API developers must ensure the sandbox is working as expected and mirrors the production environment as closely as possible. To do this, API developers can test the sandbox API from the Choreo Console by following these steps.

  1. Open the Choreo Console and open the API sandbox component.
  2. Go to the Test page. The endpoint selector will list both primary and sandbox URLs for environments with a configured sandbox endpoint.
  3. Select the endpoint you want to test and invoke the API.

Figure 3: Test API sandbox

Consuming the API Sandbox

Developers can discover APIs through the Choreo Developer Portal. When a sandbox is configured for an API, they will see two API URLs labeled as production and sandbox respectively. Application developers can use the sandbox during application development. Once it’s tested and evaluated in a development environment, the application can be promoted to production. When deploying it to production developers must change the API endpoint to the production URL of the API using these steps. 

  1. Open the Choreo Devportal.
  2. Create an application and subscribe to the APISandbox API. Generate an access token.
  3. Open the APISandbox API.
  4. Go to the ‘Try Out’ page. The endpoint selector will list both production and sandbox URLs for environments with a configured sandbox endpoint.
  5. Select the endpoint you want to test and invoke the API.

Figure 4: Consume API sandbox

Conclusion

An API sandbox provides a pseudo-production environment where applications can be tested. It helps build confidence in the application’s real-world performance and therefore is essential for the application development process. Sign up to Choreo for free and try out its new API sandbox feature today!

English