LoopBack Request node

IBM Knowledge Center

Learn how to use the LoopBackRequest node to create a JSON document in a Cloudant database

Import projects

When you click Import, an application will be created in your workspace named LoopBack.

The application LoopBack contains a message flow named LoopBack_Cloudant.msgflow which contains an HTTPInput node, LoopBackRequest node and HTTPReply node.

The HTTPInput node has a path suffix /LoopBack_Cloudant.

The LoopBackRequest node has a datasource property of CLOUDANT, and is configured to interact with a LoopBack object named share_price (in our example this is the name of the Cloudant database). The Create operation is selected so that the JSON structure passed in to the LoopBackRequest node is inserted into the Cloudant database.

Create the Cloudant Database

  1. This tutorial assumes the availability of a Cloudant database. You can use IBM Bluemix to provide this (free of charge). Sign into IBM Bluemix, find the Cloudant NoSQL DB in the Data & Analytics section of the IBM Bluemix Catalog, and create an instance.
  2. Navigate to the Service Credentials section and you will find connection details that we will be using to tell IIB how to communicate with your Bluemix Cloudant instance. They should look similar to this:
    {
    "username": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa-bluemix",
    "password": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
    "host": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa-bluemix.cloudant.com",
    "port": 443,
    "url": "https://aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa-bluemix:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb@aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa-bluemix.cloudant.com"
    }
  3. Create a database called share_price.

Configure the IIB LoopBack connector

  1. To use the LoopBackRequest node in this tutorial, you must install the Cloudant LoopBack connector. Open the IBM Integration Bus Command Console:
    cd %MQSI_WORKPATH%\node_modules
    npm install loopback-connector-cloudant
  2. If you don't already have one, create a datasources.json file in the connectors/loopback folder of your IIB workpath (by default on Windows, this will be at C:\ProgramData\IBM\MQSI\connectors\loopback). This is where IIB stores connection information for Loopback Request node instances.
  3. Add a stanza to the datasources.json file:
    { "CLOUDANT":{"database": "share_price","name": "CLOUDANT","host": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa-bluemix.cloudant.com","port": 443,"connector": "cloudant"}}
  4. From your command console configure IIB with your Cloudant security credentials like this:
    mqsisetdbparms TESTNODE_userid -n loopback::CLOUDANT_SEC_ID -u aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa-bluemix -p bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
  5. Restart your node.

Use the Flow Exerciser to test the tutorial scenario

Having prepared the scenario, the following steps describe how to use the Flow Exerciser to test the message flow:

  1. Open LoopBack_Cloudant.msgflow.
  2. Click the Flow Exerciser icon to start testing the flow
  3. Click the Send Message icon .
  4. Select the saved message which has been provided, named InputMessage, and click Send:
    {"companyID":"100","company":"IBM UK Ltd","price":199}
    Your message is sent to the HTTPInput node.
  5. A response should be shown, which now includes an id that the database has created and given to the document, which should look like this:
    {"id":"de28e5b037b01a3670d9b9f8d459deb5","companyID":"100","company":"IBM UK Ltd","price":199}
  6. After you close the dialog, the paths taken through the messageflow are highlighted. Click on the message icon on each connection to see how the tree has been updated by each node.

This tutorial has shown the LoopBackRequest node creating a JSON document in a Cloudant database.