When you want to expose data residing into a HANA database to the outside world, the recommended best practice is to use Odata.
In this blog, you will learn how to build xsodata services used to expose your data model. In the next blog, we use that Odata service to build a User Interface.
Open the SAP Web IDE, right-click the project where you created a DB module and create a new Node.js Module.
Give a name to your Node,js Module. I called mine core_xsjs
Check "Enable XSJS Support". By checking it, you enable the SAP XSJS libraries which allow you to use the programming model and APIs from the Extended Application Services, classic model.
A node.js module called core_xsjs gets created in your project.
The mta.yaml file has been extended to add the core_xsjs module.
This XSJS module will also need data from the database module and the HDI container behind it. Add those dependencies to the node module Requires section.Additionally add the UAA service for authentication if you created it. Then save and close the mta.yaml.
This step is essential : if dependencies are not declared in the mta.yaml file, your Node.js module will not be able to access the HDI container.
Create an Odata service with xsodata
Right-click the lib folder and create a new file.
This will create a new folder xsodata, and a file customers.xsodata within it.
Within customers.xsodata, paste the following code :
This code creates an Odata service v2.0 exposing the content of the table order-entry.db::customers.
You could do the same with views or virtual tables. Find out more about XSODATA.
Run and test your service
Right-click your Node.js module core_xsjs and Run it as a Node.js Application.
This will build and run the Node.js application. Click on the URL of the node.js service, and add this path at the end : /xsodata/customers.xsodata/customers?$format=json
This will access your Odata service.
Your data is now exposed to the outside world. In the next steps, we will use this Odata service to build a User Interface.