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¶
The following software and configurations are required to proceed with this tutorial:
- Visual Studio Code (VS Code): with the Micro Integrator extension installed.
- Java Development Kit (JDK): Ensure the JDK is properly configured in your system's PATH environment variable.
- Apache Maven: Ensure Apache Maven is installed and its path is correctly set within the system's PATH environment variable.
Info
Follow the Install Micro Integrator for VS Code documentation for a complete installation guide.
Step 2: Develop the integration artifacts¶
Follow the instructions given in this section to create and configure the required artifacts.
Open the integration project¶
-
Download the required project from here and extract.
-
Launch VS Code with the Micro Integrator extension installed.
-
Click on the Micro Integrator icon on the Activity Bar of the VS Code editor.
-
Click Open MI Project on Design View.
-
Provide the location of the downloaded project path.
Develop the inbound endpoint¶
-
Once you have opened the integration project described above, the Micro Integrator Project Explorer will appear with the previously created artifacts. Note that the
HealthcareAPI
is already included. -
Navigate to the MI Project Explorer > Inbound Endpoints.
-
Hover over Inbound Endpoints and click the + icon that appears.
-
On the Inbound EP Form, select HTTP as the inbound endpoint type.
-
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¶
Prerequisites
Before you begin, install Micro Integrator on your machine:
-
Go to the WSO2 Micro Integrator web page, click Download, provide necessary details, and then click Zip Archive to download the Micro Integrator distribution as a ZIP file.
-
Extract the ZIP file. The extracted folder will be referred as the
<MI_HOME>
folder.
Once you have downloaded and set up the Micro Integrator locally, follow the steps given below. Use one of the below two methods.
-
Click on the Command Palette on the top of the VS Code.
-
Type
>
to show the available commands. -
Select MI: Add MI server.
-
Select Add MI server.
-
Select the folder where
<MI_HOME>
is located. This wll be set as the current server path. -
Run the project.
Click the Build and Run icon located in the top right corner of the VS Code.
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¶
- Download the JAR file of the back-end service from here.
- Open a terminal, navigate to the location where you saved the back-end service.
-
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:
-
Open the Postman application. If you do not have the application, download it from here : Postman
-
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:
- Install and set up cURL as your REST client.
-
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
}
]