Skip to Content

In this blog we would concentrate on a nodeJS application which is deployed on cloud foundry which exposes an API. We use destination service bound to a UI5 application to make an outbound communication to the nodeJS application.

 

So, what is destinations

Connectivity destinations are part of SAP Cloud Platform Connectivity and are used for the outbound communication of a cloud application to a remote system. They contain the connection details for the remote communication of an application. Connectivity destinations are represented by symbolic names that are used by on-demand applications to refer to remote connections. The connectivity service resolves the destination at runtime based on the symbolic name provided. The result is an object that contains customer-specific configuration details. These details contain the URL of the remote system or service, the authentication type, and the relative credentials.

 

Now let’s get our hands dirty.

  1. As I said at the beginning we have 2 modules, the first one being the UI5 module which can be created using the following blog here

2.   Once UI5 application is done lets create a nodejs application which provides an API.

  • a. Setup a nodejs environment on your local machine by downloading Download | Node.js. Once the installation is complete, open command prompt and check the version of node by executing “node -v”

 

  • To the above code lets add one more api in start.js, below is the code.

 

const users = require(‘./users.json’);

app.get(‘/users’, function (req, res) {
console.log(“Get All Request “);

res.status(200).json(users);
});

  •     Create a file users.json in the root folder with dummy data like.
[
{
“first name”: “akarsh”,
“last name “: “sidhartha”,
“material”: “sponge”,
“id”: 0
},
{
“first name”: “manju”,
“last name “: “baburo”,
“material”: “sponge”,
“id”: 0
},
{
“first name”: “hari”,
“last name “: “mahi”,
“material”: “sponge”,
“id”: 0
}
]

 


Time to deploy the nodejs application on to SAP CF.

 

  •  find the correct API URL for your Region. for complete list here is the link
  • In the CLI type cf api and enter you API URL 

 

  • once the API region is set, login to CF using cf login command, 

 

  • now in the root folder of the nodejs application do a cf push in CLI.
  • once the application is deployed got the application in applications section of space, click on the application route. A new tab is opened with display as “Main Page!!”.
  • now to the url add “/users”  you will see the list of users which you created in users.json file.

Lets go ahead and create destinations for the above url.

 

  1. Expand connectivity in the sub account level, choose destinations
  2. click on new destinations and enter details as below.
  3. Note : In the Url section, mention only the url and not the subpath i.e (“/users”). the subpath will be mentioned in the xs-app.json below.

Make the changes in the UI application to call the destination API.

  1. Add getUsers destinations in xs-app.json here is the code 
  2. call the destinations from View1.controller.js file
  3. deploy the UI5 application back to CF from Webide

Now when you run the UI5 application and add breakpoint in onInit function, you would receive a success message for the destination call.

 

A complete source code is available over here

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply