This blog is part of a blog series which shows to build HANA database artefacts using the SAP WebIDE Full-Stack and the new HANA service on Cloud Foundry.
In this section, I am going to show how to create a nodejs module and add an OData service within it. This OData service will be used to expose the contents of the table/view modeled earlier.
Select the project “ProductsApp01” (created earlier) and use the context menu to create a “Node.js module”.
Create Nodejs. Module
In this section, I am going to show how to create a nodejs module and add an OData service within it. This OData service will be used to expose the contents of the table/view modeled earlier.
Select the project “ProductsApp01” (created earlier) and use the context menu to create a “Node.js module”.
Provide the name of the module as “products01_js” and enable XSJS support before clicking on Finish
Select the lib folder and use the context menu to create a new file with the name “products01.xsodata”
Paste the below code into the xsodata file
service {
"products01_db::catalog.product" as "Products"
keys ("Id");
}
Below is how your XSOData file would look like:
Modify the yaml file by selecting the nodejs module and under “Requires” section, add two dependencies. This will enable the nodejs module to refer to the DB artefacts.
Build the nodejs module by selecting the folder and using the Build option in the context menu
You should see a success message in the log files..
Run the nodejs application using the menu option shown below.
This will take few minutes. You will get a URL in the console as shown below.
Click on the URL and change it to refer the OData service as shown below
Let’s deploy this application in our Cloud Foundry runtime. Select the root project folder and use the context menu to Build the project
In few minutes, you should be able to the successful build and new folder would get created in your workspace with the .mtar file.
Deploy the mtar file to the Cloud Platform account using the context menu. When prompted for Cloud Foundry details – select your CF API Endpoint, Organization and space
This will take you few minutes to deploy the applications to your CF space.
Once the application has been deployed, navigate to your CF space and under Applications menu, you will be able to see one app for db module and another for js module. The products01_db app would be stopped by default and is only required for the creation of the DB artefacts. Also note there in another app with a long GUID. This app was created when you tried to test the nodejs module from within WebIDE. You can stop this app as its not required. We will be using the app “products01_js” as it will provide the OData service.
Click on the js app to view the application URL.
Modify the URL to call the OData service as shown below and open it in the browser.
{"d":{"results":[{"__metadata":{"uri":"https://oneflp-cal-dev-products01-js.cfapps.eu10.hana.ondemand.com/products01.xsodata/Products(101)","type":"default.ProductsType"},"Id":101,"name":"Notebook","supplierName":"IBM","category":"Computer","unitPrice":2300,"unitsInStock":34},{"__metadata":{"uri":"https://oneflp-cal-dev-products01-js.cfapps.eu10.hana.ondemand.com/products01.xsodata/Products(102)","type":"default.ProductsType"},"Id":102,"name":"Tablet","supplierName":"Samsung","category":"Computer","unitPrice":900,"unitsInStock":22},{"__metadata":{"uri":"https://oneflp-cal-dev-products01-js.cfapps.eu10.hana.ondemand.com/products01.xsodata/Products(103)","type":"default.ProductsType"},"Id":103,"name":"iPhone","supplierName":"Apple","category":"Phone","unitPrice":800,"unitsInStock":129},{"__metadata":{"uri":"https://oneflp-cal-dev-products01-js.cfapps.eu10.hana.ondemand.com/products01.xsodata/Products(105)","type":"default.ProductsType"},"Id":105,"name":"iPod","supplierName":"Apple","category":"Music","unitPrice":700,"unitsInStock":298}]}}
This should return the list of products. You can now use this URL with other SAP CP services or build a UI on top of it too.
No comments:
Post a Comment