Lab 05 - Fuse Online

Return to Workshop

Lab 5

Fuse Online




Overview

When it comes to quick API development, you need both the integration experts as well as application developers to easily develop, deploy the APIs. Here is how to create a simple API with Fuse online.

Why Red Hat?

Red Hat Fuse integration solution empowers integration experts, application developers, and business users to engage in enterprise-wide collaboration and high-productivity self-service.

##Lab Instructions

Step 1: Create database connection

  1. Navigate to OpenShift.

  2. Click on your Tools Project.

  3. Click on your Fuse Online Route and Log In.

  4. 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.




  5. Click on Connections > Create Connection




  6. Select Database




  7. Enter below values for Database Configuration

    Connection URL: jdbc:postgresql://postgresql.OCPPROJECT.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

  8. Click Validate and verify if the connection is successful. Click Next to proceed.




  9. Add Connection details:

    • Connection Name: LocationDB
    • Description: Location Database
    • Click Create.




  10. Verify that the Location Database is successfully created.

Step 2: Create webhook integration

Description goes here

  1. Click on Integrations > Create Integration




  2. Choose Webhook




  3. Click on Incoming webhook




  4. It navigates to the Webhook Token screen. Click Next




  5. 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"
      }
    }
    





  6. Click on LocationDB from the catalog and then select Invoke SQL




  7. 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 )
    




  8. Click on Add step and select Data mapper




  9. Drag and drop the matching Source Data types to all their corresponding Targets as per the following screenshot. When finished, click Done.




  10. Click Publish on the next screen

  11. Add Integration Name: addLocation.

  12. Again Click Publish.




Congratulations. You successfully published the integration. (Wait for few minutes to for the integration to be built and published)

Step 3: Create a POST request

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.

  1. Copy the External URL per the below screenshot




  2. Open a browser window and navigate to: https://onlinecurl.com/

  3. Below are the values for the request.

    • Past the URL you just copied for the curl command
    • Click "+ ADD Option" 3 times
      • for --request (x) enter:
        • POST
      • for --data (-d) enter:
        • {"id": 101, "name": "Kamarhati", "type": "Regional Branch", "status": "1", "location": { "lat": "-28.32555", "lng": "-5.91531" }}
      • for --header (-H)
        • Content-Type: application/json
    • Note: id:101 in the payload as we are creating 101th record in the database.
    • Click START YOUR CURL




  4. The page will load the 204 response information from the service which means the request was successfully fulfilled.

    • If you get an SSL error, please see the next step.




  5. If you are using an Environment with self signed certificates and get an SSL error, you can also use the curl utility in the terminal of your Eclipse Che environment instead of online curl.

    • 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
    
  6. Click on Activity > Refresh and verify if the newly record is created.




  7. (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"
      }
    }

Summary

In this lab you discovered how to create an adhoc API service using Fuse Online.

Notes and Further Reading

Return to Workshop