Skip to content

How to Use Inbound Endpoints

What you'll build

In this sample scenario, you will use an Inbound Endpoint to expose an already defined REST API through a different port. You can reuse the REST API that was defined in the Sending a Simple Message to a Service tutorial.

Let's get started!

Step 1: Set up the workspace

You need Visual Studio Code (VS Code) with the WSO2 Integrator: MI for VS Code extension installed.

Info

See the Install WSO2 Integrator: MI for VS Code documentation to learn how to install WSO2 Integrator: MI for VS Code.

Step 2: Develop the integration artifacts

Follow the instructions given in this section to create and configure the required artifacts.

Open the integration project

  1. Download the required project from here and extract.

  2. Launch VS Code with the WSO2 Integrator: MI extension installed.

  3. Click on the WSO2 Integrator: MI icon on the Activity Bar of the VS Code editor.

    MI VS Code Extension

  4. Click Open MI Project on Design View.

  5. Provide the location of the downloaded project path.

Develop the inbound endpoint

  1. Once you have opened the integration project described above, the WSO2 Integrator: MI Project Explorer will appear with the previously created artifacts. Note that the HealthcareAPI is already included.

    Inbound project explorer

  2. Click the + icon in the MI Project Explorer.

    create inbound endpoint

  3. Select the Event Integration and click it.

    add inbound endpoint

  4. On the Create Event Integration panel, select HTTP as the inbound endpoint type.

  5. Enter the following details and click Add.

    Parameter Description
    Inbound Endpoint Name QueryDoctorInboundEndpoint
    Injecting Sequence Name TestIn
    Error Sequence Name fault
    Inbound HTTP port 8285
    Dispatch Filter Pattern /healthcare/querydoctor/.*

The endpoint will now be mapped to any URL that matches the pattern provided above. You will expose the healthcare API on a new port through this inbound endpoint.

Step 3: Build and run the artifacts

Click the Build and Run icon located in the top right corner of the VS Code.

Build and run

Step 4: Test the use case

Let's test the use case by sending a simple client request that invokes the service.

Start the backend service

  1. Download the JAR file of the back-end service from here.
  2. Open a terminal, navigate to the location where you saved the back-end service.
  3. Execute the following command to start the service:

    java -jar Hospital-Service-JDK11-2.0.0.jar
    

Send the client request

Let's send a message to the healthcare REST API (through the inbound endpoint) on port 8285. You can use Postman or any other HTTP Client:

  1. Open the Postman application. If you do not have the application, download it from here : Postman

  2. Add the request information as given below and click the Send button.

    Method GET
    URL http://localhost:8285/healthcare/querydoctor/surgery





If you want to send the client request from your terminal:

  1. Install and set up cURL as your REST client.
  2. Open a command line terminal and execute the following command:

    curl -v http://localhost:8285/healthcare/querydoctor/surgery
    

You will get the response shown below. The inbound endpoint has successfully invoked the REST API, and further, the response received by the REST API has been routed back to the client through the inbound endpoint.

[
    {
        "name": "thomas collins",
        "hospital": "grand oak community hospital",
        "category": "surgery",
        "availability": "9.00 a.m - 11.00 a.m",
        "fee": 7000.0
    },
    {
        "name": "anne clement",
        "hospital": "clemency medical center",
        "category": "surgery",
        "availability": "8.00 a.m - 10.00 a.m",
        "fee": 12000.0
    },
    {
        "name": "seth mears",
        "hospital": "pine valley community hospital",
        "category": "surgery",
        "availability": "3.00 p.m - 5.00 p.m",
        "fee": 8000.0
    }
]