Skip to Content
Technical Articles

Use xsodata to expose HANA Cloud tables as Odata services

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.
xsodata services uses the proprietary XSJS dialect of Javascript to create an Odata service. In order to use XSJS, SAP adds Node.js modules to provide XSJS compatibility.

This content is based on the tutorial by Thomas Jung, SAP HANA XS Advanced, creating a Node.js module.Expose%20data%20residing%20in%20SAP%20HANA%20Cloud%20via%20Odata%20services

Expose data residing in SAP HANA Cloud via Odata services

 

Prerequisites

 

Create a Node.js module in your project

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.

Input xsodata/customers/xsodata
This will create a new folder xsodata, and a file customers.xsodata within it.

Within customers.xsodata, paste the following code :

service {
	"order-entry.db::customers"
	  as "customers";
}

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.

2 Comments
You must be Logged on to comment or reply to a post.
  • Hi,

     

    I have just tried this now and all was going well until I tried to run the URL with the additional /xsodata/customers.xsodata/customers?$format=json at the end of the URL. 

    I get this error : –

     

    “Invalid HANA setting provided. OData services are disabled….”

     

    Would you know what this is and how it can be rectified.

     

    Is this method the only way to expose a table as an OData service?

     

    Thanks

    Martin