Skip to main content

Build an Integration as API

Cloud has the newest features. Some may not be in a release yet; the newest release is Integration 5.1.0.
  • Time: Under 10 minutes
  • What you'll build: An HTTP service that listens on /hello/greeting, calls an external API, and returns the response to the caller.

An HTTP service exposes your integration logic as a REST endpoint. This quick start shows the full cycle: create a service, add a resource, connect to an external API, and test it using the Try-It/Test panel in Choreo Integrator.

Prerequisites​

A working Choreo Integrator environment.

  • Choreo Cloud setup: Sign up and launch Choreo Integrator in the browser-based cloud editor.

Step 1: Create the integration​

  1. On the project overview page, click Open Cloud Editor.

    How would you like to create your integration page with Open Cloud Editor highlighted under Create on Cloud

  2. The Choreo Integrator cloud editor opens in your browser.

    Cloud editor landing page with Choreo Integrator Copilot, the Add Artifact manually button, and the Deploy to Choreo Cloud panel

Note

The cloud editor creates a default integration for you, so you don't need to name it now. You can change its name when you deploy it. For more information, see Save and deploy.

Step 2: Add an HTTP service​

  1. In the design view, click Add Artifact manually.

    Integration design view with the Add Artifact manually button highlighted

  2. Select HTTP Service under Integration as API.

    Artifacts page with HTTP Service highlighted under Integration as API

  3. Keep Service Contract as Design From Scratch.

  4. Set Service Base Path to /hello.

  5. Click Create.

    Create HTTP Service form with Service Base Path set to /hello

Step 3: Add a resource​

  1. In the HTTP service design view, click + Add Resource.

  2. Select GET.

    Select HTTP Method to Add panel with GET highlighted

  3. Set Resource path to greeting.

  4. Click Save.

    New Resource Configuration panel with Resource Path set to greeting

Step 4: Connect to an external API​

  1. Click + inside the resource flow.

    Resource flow with the add node button highlighted

  2. Click Add Connection under Connections.

    Node panel with Add Connection highlighted under Connections

  3. Select HTTP under Pre-built Connectors.

    Add Connection dialog with the HTTP connector highlighted under Pre-built Connectors

  4. The Connect to Third-Party service form opens. Set Url to:

    https://apis.wso2.com/zvdz/mi-qsg/v1.0

    Connect to Third-Party service form with Url set

  5. Scroll to the bottom of the form. Set Connection Name to externalApi.

  6. Click Save Connection.

    Connect to Third-Party service form with Connection Name set to externalApi

Step 5: Call the external API​

  1. Click + inside the resource flow.

    Resource flow with the add node button highlighted

  2. Select externalApi.

  3. Select Get.

    Node panel with the externalApi connection and its Get action highlighted

  4. Set Path to /.

  5. Set Result to response.

  6. Set Target Type to json.

  7. Click Save.

    externalApi get form with Path, Result, and Target Type set

Step 6: Return the response​

  1. Click + inside the resource flow, below the external API call node you just added.

    Resource flow with the add node button highlighted after the http node

  2. Select Return under Control.

    Node panel with Return highlighted under Control

  3. In the Expression field, select response from the variables.

  4. Click Save.

    Return panel with Expression set to response

Step 7: Run and test​

  1. Click Run.

  2. Click Test in the confirmation dialog.

  3. Click Execute.

  4. Confirm the response shows 200 OK with a Hello World body.

    Running the integration and testing it with the Try It panel showing a 200 OK response

Step 8: Deploy to Choreo Cloud​


To deploy your integration to Choreo Cloud from the cloud editor, see Save and deploy.

Skip ahead: deploy a ready-made sample

Rather not build it yourself? Deploy the Hello World Service sample straight to Choreo Cloud. See Start with sample integrations.

Source code​

View the generated Ballerina code

The steps above generate the following complete, runnable Ballerina program:

import ballerina/http;

listener http:Listener httpDefaultListener = http:getDefaultListener();

final http:Client externalApi = check new ("https://apis.wso2.com/zvdz/mi-qsg/v1.0");

service /hello on httpDefaultListener {

resource function get greeting() returns json|error {
do {
json response = check externalApi->get("/");
return response;
} on fail error err {
// handle error
return error("unhandled error", err);
}
}
}

Was this page helpful?