Skip to Content
Technical Articles
Author's profile photo Deep Ganguly

Data as Service -Create your Data-as-a-Service API-Part 1/2

Data as a Service helps businesses to store data in centralized place often know as data lakes where data is aggregated,cleansed and enriched before offering it to applications ,mobile users or different systems – irrespective of where they were via APIs. The APIs can further me governed and metered to adapt a pay-per-use model.

Through this blog series I would explain how SAP API Management can be leveraged to realize this scenario. The following are the total steps involved

  • Provision the API-Create API and expose Data
  • Govern the APIs-use SAP API management to govern the APIs
  • Monetize the APIs- bundle APIs and monetize then
  • Consume the API within an application

Overview Diagram

 

Provision the API-Create OData API to expose Data

Here we are going to take the advantage of SAP Cloud Platform Trial Account to create a database in the HANA DB and then expose this data as an OData API with the help of HANA xs engine. But first we need data . We are going to use the Nutrient data offered by USDA which contains the Nutrient information.Click here to download the csv file.

Once downloaded use the as  SAP Cloud Platform Trial Landscape to log-in to your account.->Databases & Schemas. Create a db and then go to the ‘SAP HANA Web-Based Development Workbench‘->create a package named nutrient..within the package the following files are to be placed.

 

#NutrientOData.hdbdd
namespace nutrient;
@Schema: 'nutrient'
context NutrientOData { @Catalog.tableType: #COLUMN
    entity NutrientDetails {
    
    name:String(255);
    grouping:String(255);
    protein:Double;
    calcium:Double;
    sodium:Double;
    fiber:Double;
    vitaminc:Double;
    potassium:Double;
    carbohydrate:Double;
    sugars:Double;
    fat:Double;
    water:Double;
    calories:Double;
    saturated:Double;
    monounsat:Double;
    polyunsat:Double;
    key id:Integer not null;
}; 
};  
#nutrientrole.hdbrole

role nutrient::nutrientrole extends role sap.hana.admin.cockpit.sysrep.roles::SysRepAdmin
{
system privilege: REPO.IMPORT;


}
#nutrient.hdbschema
schema_name = "nutrient";
#importcsv.ctl
IMPORT FROM  'nutrient.csv' INTO  "nutrient::NutrientOData.NutrientDetails"
#.xsprivileges

{  
"privileges": [  
  {"name": "Execute", "description": "Execute"}
]  
} 
#.xsapp
{} 
#.xsaccess
{
    "exposed": true,
    "prevent_xsrf": true,
    "authentication": [{
         "method": "Basic"
        }],
    "authorization": ["nutrient::Execute"] 
}   
#odataservicerole.hdbrole
role nutrient.role::odataservicerole extends role nutrient::nutrientrole
{
system privilege: CREATE SCHEMA;

schema nutrient:nutrient.hdbschema: EXECUTE, SELECT, INSERT, UPDATE, DELETE, CREATE ANY, ALTER, DROP, INDEX, TRIGGER, REFERENCES, DEBUG;


package nutrient: REPO.READ, REPO.EDIT_NATIVE_OBJECTS, REPO.ACTIVATE_NATIVE_OBJECTS, REPO.EDIT_IMPORTED_OBJECTS, REPO.MAINTAIN_NATIVE_PACKAGES, REPO.MAINTAIN_IMPORTED_PACKAGES, REPO.ACTIVATE_IMPORTED_OBJECTS;
package nutrient.role: REPO.READ, REPO.EDIT_NATIVE_OBJECTS, REPO.ACTIVATE_NATIVE_OBJECTS, REPO.EDIT_IMPORTED_OBJECTS, REPO.ACTIVATE_IMPORTED_OBJECTS, REPO.MAINTAIN_IMPORTED_PACKAGES, REPO.MAINTAIN_NATIVE_PACKAGES;

application privilege: "nutrient::Execute";

}
#NutrientService.xsodata
service
{
 "nutrient::NutrientOData.NutrientDetails" as "Nutrient";
}

 

After the above code is activated the OData service should be up and running. The following url should give all the data https://***.hana.ondemand.com/nutrient/NutrientService.xsodata/Nutrient.

This ends the provisioning of the OData API. The next part is to govern and monetize this API upon consumption.

Part 2

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.