Skip to content

Develop Integration as API

Overview

In this guide, you will create a simple integration as an API that acts as a service that calls a third-party endpoint and returns its response to the client.

introduction

Prerequisites

Before you begin, make sure you have the following:

Step 1: Create a new integration project

  1. Click on the BI icon on the sidebar.
  2. Click on the Create New Integration button.
  3. Enter the Integration Name as HelloWorld.
  4. Select the project directory by clicking on the Select Path button.
  5. Click on the Create Integration button to create the integration project.

    Create Integration

Step 2: Create an integration service

Generate with AI

The integration service can also be generated using the AI-assistant. Click on the Generate with AI button and enter the following prompt, then press Add to Integration to generate the integration service.

Create an http service that has base path as /hello, and 9090 as the port. Add GET resource on /greeting that invokes https://apis.wso2.com/zvdz/mi-qsg/v1.0 endpoint and forward the response to the caller.

  1. In the design view, click on the Add Artifact button.
  2. Select HTTP Service under the Integration as API category.
  3. Select the Design From Scratch option as the Service Contract.
  4. Specify the Service base path as /hello.
  5. Click on the Save button to create the new service with the specified configurations.

    Create Service

Step 3: Design the integration

  1. Click on Add Resource button and select GET HTTP method.
  2. Change the resource path to greeting and click the Save button.

    Create Service

  3. Click the ➕ button to add a new action to the resource.

  4. Select Add Connection from the node panel.
  5. Search for HTTP in the search bar and select HTTP as the connection type.
  6. Add the URL "https://apis.wso2.com" to the connection URL field.
  7. Change the Connection Name to externalEp and click Save.
  8. Select Connections -> externalEp -> get from the node panel. Set /zvdz/mi-qsg/v1.0 as Path, epResult as Result, and string as Target Type.
  9. Fill in the request details as below and click Save.

    Create New Connection

  10. Click ➕ button again and select Return from the node panel.

  11. Select the epResponse variable as the Expression from the dropdown and click Save. This step will return the response from the HelloWorld API endpoint.

    Invoke Endpoint

Step 4: Run the integration

  1. Click on the Try It button in the top right corner to run the integration.
  2. If the integration is not running, there will be notification messaging asking to run the integration.
  3. Click Run Integration if a notification is appeared.
  4. Once the integration is started, Try-it will open up on the right side.
  5. Click on the Run button to invoke the greeting resource.

    Run Integration

  6. Additionally, you can test the integration using REST clients like Postman or curl.

    curl http://localhost:9090/hello/greeting
    {"message":"Hello World!!!"}%
    
  7. Click on the âšī¸ button or press Shift + F5 shortcut to stop the integration.

    Stop Integration