Skip to Content
Technical Articles
Author's profile photo ASUTOSH MAHARANA

Low Code Approach for API Development

Introduction

Low-code development is a way to build software applications faster by reducing the need to write code. With a low-code application development platform, you can use visual development tools—such as drag-and-drop modelers and point-and-click interface creation—to enable the rapid creation, deployment, and maintenance of powerful business apps. Low-code programming is expected to have a dominant position in the future of business application development. Gartner predicts that more than 65% of all business apps will be built using low code by 2024.

Main

In this blog we will create a microservice which will be used by a simple work time tracking tool. We will create and deploy an application in SAP Cloud Foundry which will use SAP HANA as database and expose the OData service via SAP API Management to frontend application developers. This is just a sample scenario for tutorial purpose.

SAP Business Application Studio

  • Navigate to SAP Business Application Studio instance of your Business Technology Platform and create a Dev space.Creation%20of%20Dev%20Space%20in%20SAP%20Business%20Application%20Studio

    Creation of Dev Space in SAP Business Application Studio

  • From the main menu of SAP Business Application Studio, choose Terminal > New Terminal.
  • Run the following command in the newly created terminal to go back to the projects folder:
    cd ~/projects
  • Then run the following command. This will initialize the application using the maven archetype cds-services-archetype and create project.
    mvn -B archetype:generate -DarchetypeArtifactId=cds-services-archetype -DarchetypeGroupId=com.sap.cds \
    -DarchetypeVersion=RELEASE \
    -DgroupId=com.asu.cap -DartifactId=work-time -Dpackage=com.asu.cap.worktime
    
  • Navigate to “work-time” folder and create two files name “schema.cds” and “services.cds” under “db” and “srv” folder respectively. Then you can either model the CDS files using graphical editor or paste below JSON structures.
  • schema.cds
    namespace sap.asu.tracker;
    
    entity Registry {
        key empid      : Integer;
        key date       : Date;
            logintime  : Time not null;
            logofftime : Time not null;
    }
    
  • services.cds
    using {sap.asu.tracker as db} from '../db/schema';
    
    service Tracker {
        entity RecordYourTime as projection on db.Registry;
    
        @readonly
        entity DispayRecords  as projection on db.Registry;
    
        entity Admin          as projection on db.Registry;
    }
    
  • Run the following command to install the necessary node packages.
    npm install --save-dev @sap/hdi-deploy​

    Creation%20of%20Project

  • Add the following configuration in the file “.cdsrc.json”
    {
        "hana": {
            "deploy-format": "hdbtable"
        }
    }
  • Then create a new SAP HANA Schemas and HDI container Trial instance in SAP BTP cockpit and name it “HANADB”.
  • Run the following command.
    cf api <CF_API_ENDPOINT>​
  • Run the following command.
    cf login​
  • Then run below command in terminal to implicitly push all artifacts to the database.
    cds deploy --to hana:HANADB​
  • Create a new file called “manifest.yml” in the root folder of the project and add below code.
    ---
    applications:
    - name: WorkTimeTracker
      path: srv/target/work-time-exec.jar
      random-route: true
      services:
      - HANADB
    ​
  • Add the following dependency under the <dependencies> tag of pom.xml file in the “srv” directory.
    <dependency>
      <groupId>com.sap.cds</groupId>
      <artifactId>cds-feature-hana</artifactId>
    </dependency>
    <dependency>
      <groupId>com.sap.cds</groupId>
      <artifactId>cds-feature-cloudfoundry</artifactId>
    </dependency>
    ​
  • Build the application once by running.
    mvn clean install
  • Push the application to the cloud by running.
    cf push

Deploy%20application%20in%20SAP%20CF

Deploy application in SAP CF

  • Then check the terminal logs for routes and copy the URL for calling the service.You can go to HANA Database Explorer and add some records in the table.

Insert%20data%20into%20HANA%20table

Insert data into HANA table

SAP API Management

  • We can create API provider first for our microservice. For this navigate to “Configure” and click on create. Then provide the host as the microservice URL and port as 443 and check SSL. Then save and test the connectivity.
  • Then we can create two API proxy one for Employee and another for Admin. We can navigate to “Develop” and click on create and configure as per below screenshot.

Creation%20of%20API%20Provider%20and%20API%20Proxy

Creation of API Provider and API Proxy

  • Then we can go to “resource” tab and remove the required resources from each API proxy. Then save and deploy the proxy. (So that Employee will not have access to use Delete method)

Update%20Resources%20of%20API%20Proxy%20according%20to%20requirements

Update Resources of API Proxy according to requirements

  • Then click on “save” and “policies” button to implement policy. On the next page click on edit and add “Verify APIKey” policy to preflow of proxy endpoint. Then add below code.
    <!--Specify in the APIKey element where to look for the variable containing the api key--> 
    <VerifyAPIKey async='true' continueOnError='false' enabled='true' 
    xmlns='http://www.sap.com/apimgmt'>
    	<APIKey ref='request.header.APIKey'/>
    </VerifyAPIKey>
    
  • Now save and deploy the API Proxies
  • Navigate to product tab and create two products for Admin and Employee API Proxy.
  • Navigate to API Business Hub to create two applications for both of the products respectively.
  • Now you can test the APIs in api business hub by using generated APIKey.

API%20Business%20Hub%20configuration

API Product and Application creation for API Proxies

Conclusion

This is just a basic scenario by which we can create and expose one OData service using SAP Business Application Studio and SAP API Management. You can explore Cloud Application Programming Model of SAP for further details. This blog is only to illustrate the capabilities of low code approach of SAP, which is very helpful to create cloud applications easily.

Thanks for reading 🙂

Assigned tags

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