<img src="../images/agenda-03.png “Login” width=“900” />
When it comes to quick API development, you need both the integration experts as well as application developers to easily develop and deploy the APIs. Here is how to create a simple API with Fuse Online.
Red Hat Fuse integration solution empowers integration experts, application developers, and business users to engage in enterprise-wide collaboration and high-productivity self-service.
Navigate to OpenShift.
Click on your Tools Project.
Click on your Fuse Online Route and Log In.
The first time that you hit the Fuse Online URL, you will be presented with an Authorize Access page. Click the Allow selected permissions button to accept the defaults.
<img src="../images/design-54.png “Accept permissions” width=“900” />
Click on Connections > Create Connection
<img src="../images/00-create-connection.png “Create Connection” width=“900” />
Select Database
<img src="../images/01-select-database.png “Select Database” width=“900” />
Enter below values for Database Configuration
Connection URL: jdbc:postgresql://postgresql.international.svc:5432/sampledb
Username : dbuser
Password : password
Schema : <blank>
Remember to replace the OCPPROJECT with the OpenShift project(NameSpace) you used in last lab. It should be your username
Click Validate and verify if the connection is successful. Click Next to proceed.
<img src="../images/02-click-validate.png “Validate” width=“900” />
Add Connection details:
Connection Name: LocationDB
Description: Location Database
Click Create.
<img src="../images/03-connection-details.png “Add Connection Details” width=“900” />
Description goes here
Click on Integrations > Create Integration
<img src="../images/04-create-integration.png “Create Integration” width=“900” />
Choose Webhook
<img src="../images/05-choose-weebhook.png “Choose webhook"Integration” width=“900” />
Click on Incoming webhook
<img src="../images/06-incoming-webhook.png “Add incoming webhook” width=“900” />
It navigates to the Webhook Token screen. Click Next
<img src="../images/07-webhook-configuration.png “Webhook Configuration” width=“900” />
Define the Output Data Type.
Select type from the dropdown as JSON instance.
Enter Data type Name: Custom
For Definition:, copy below JSON data.
Click Done
{
"id": 1,
"name": "Kamarhati",
"type": "Regional Branch",
"status": "1",
"location": {
"lat": "-28.32555",
"lng": "-5.91531"
}
}
<img src="../images/08-data-type.png “Data Type” width=“900” />
Click on LocationDB from the catalog and then select Invoke SQL
<img src="../images/09-invoke-sql.png “Invoke SQL” width=“900” />
Enter the SQL statement and click Done.
INSERT INTO locations (id,name,lat,lng,location_type,status) VALUES (:#id,:#name,:#lat,:#lng,:#location_type,:#status ) ```
<br><img src="../images/10-invoke-sql-2.png "Invoke SQL 2" width="900" /><br><br>
Click on Add step and select Data mapper
<img src="../images/11-data-mapper.png “Data Mapper” width=“900” />
Drag and drop the matching Source Data types to all their corresponding Targets as per the following screenshot. When finished, click Done.
<img src="../images/12-configure-mapper.png “Configure Mapper” width=“900” />
Click Publish on the next screen
Add Integration Name: addLocation.
Again Click Publish.
<img src="../images/13-publish-integration.png “Publish Integration” width=“900” />
Congratulations. You successfully published the integration. (Wait for few minutes to for the integration to be built and published)
We will use an online cURL tool to create the 101st record field in database. If you’d prefer to use the Terminal in your Che instance, go ahead and skip the online cURL instructions and just use the cURL command in your Che Terminal.
Copy the External URL per the below screenshot
<img src="../images/14-copy-URL.png “Copy URL” width=“900” />
Open a browser window and navigate to: https://onlinecurl.com/
Below are the values for the request.
Past the URL you just copied for the curl command
Click “+ ADD Option” 3 times
Note: id:101 in the payload as we are creating 101th record in the database.
Click START YOUR CURL
<img src="../images/15-online-curl.png “Online URL” width=“900” />
If you get an SSL error, please see the next step.
<img src="../images/16-response-header.png “Response Header” width=“900” />
Please make sure to use the your URL you copied and pasted
curl -k \
--header "Content-Type: application/json" \
--request POST \
--data '{"id": 101, "name": "Kamarhati", "type": "Regional Branch", "status": "1", "location": { "lat": "-28.32555", "lng": "-5.91531" }}' \
https://i-addlocation-tools1.apps.ocp-ai.redhatgov.io/webhook/KcZ3E86SUJTqIUsA8iB7Yb5Sa1KLp9cchnRO5twYnr6UTruYd1
Click on Activity > Refresh and verify if the newly record is created.
<img src="../images/17-activity-refresh.png “Activity Refresh” width=“900” />
(Optional) Visit the application URL in the browser from the Location Service created in the previous lab and verify if the record can be fetched.
RESPONSE
{
"id" : 101,
"name" : "Kamarhati",
"type" : "Regional Branch",
"status" : "1",
"location" : {
"lat" : "-28.32555",
"lng" : "-5.91531"
}
}
In this lab you discovered how to create an adhoc API service using Fuse Online.