SAP Cloud SDK and SAP Cloud Application Programming Model

Objectives

After completing this lesson, you will be able to:

  • Introduce the relationship between SAP Cloud SDK and SAP Cloud Application Programming model

Introduction

You might wonder how the SAP Cloud SDK and SAP Cloud Application Programming Model (SAP CAP Model) are related.  Also, what the recommended approach is, for building enterprise grade applications and services within the SAP ecosystem.  This lesson will give you a brief insight into SAP CAP Model and how it leverages the capabilities of the SAP Cloud SDK.

SAP Cloud Application Programming model (SAP CAP model)

SAP CAP Model simplifies building enterprise grade services and applications.  It guides developers along a 'golden path' of proven best practices.  Since best practices are served out-of-the-box with generic solutions for many recurring tasks, developers can focus on the business logic without having to worry about the underlying technical details.  This results in accelerated development, minimized boilerplate code as well as increased quality.  When it comes to building enterprise grade applications and services on SAP BTP, SAP CAP Model is the recommended approach.

Relationship between SAP Cloud SDK and SAP CAP model

SAP CAP Model is fully compatible with SAP Cloud SDK.  In fact, SAP CAP Model uses SAP Cloud SDK behind the scenes to perform a variety of tasks.  For example, to connect to any remote system in the SAP CAP Model, we make use of the following code snippet…

Code snippet
await cds.connect.to("remoteService");
Expand

SAP CAP Model behind the scenes uses the SAP Cloud SDK to retrieve the technical information about the remote target system from the destination configured in SAP BTP. It is then able to make a connection to the remote system passing in the proper credentials.

Similarly, when it comes to multi-tenancy support, SAP CAP Model needs to be aware of the tenant context in the request object. This again is supported by SAP Cloud SDK. So, we see how SAP CAP Model leverages the capabilities of the SAP Cloud SDK to simplify application development.

When to use SAP Cloud SDK ?

Scenario 1

For the most part, when building applications using the SAP CAP Model, you will not even be aware that it is using the SAP Cloud SDK behind the covers.  In fact, the recommendation in SAP CAP Model when connecting to remote services is not to directly leverage the SAP Cloud SDK.  But there are times when you might want to directly leverage the SAP Cloud SDK from within the SAP CAP Model application.  For example, if you have a requirement within your CAP application to retrieve the JWT token from the request object, then you can do so with the following code. 

Code snippet

const { retrieveJwt } = require("@sap-cloud-sdk/core");
const jwt = retrieveJwt(req);
Expand

SAP CAP Model is fully compatible with SAP Cloud SDK.  So even though, CAP Model hides the complexity to the developer, you could still directly leverage the SAP Cloud SDK to perform custom logic. 

Scenario 2

If you are planning to build your application using MongoDB, then you will not be able to use the CAP Model (since it only supports HANA for production).  In this case, you will have to build your application without using the CAP Model.  In such scenarios, more than likely you will need to use the SAP Cloud SDK for connecting to remote systems, consuming APIs in a type-safe manner etc.  You can also use the SAP Cloud SDK to secure your application, provide multi-tenant support etc. 

Of course, this scenario is not restricted to supporting MongoDB - but any scenario where you decide not to use the CAP Model for any reason.  In all these scenarios, you will use the SAP Cloud SDK directly to build your extension applications. 

Scenario 3

If you already have an existing Java application that was built without using the SAP CAP Model and you want to add more features to it.  Here again, you can make use of the SAP Cloud SDK tool set. 

Scenario 4

If you need advanced features in your app (currently, not provided by CAP Model) - for example, Resilience.  SAP Cloud SDK also allows you to generate the Virtual Data Model (VDM) of custom OData Services as well as standard SAP OData Services.  This VDM can then be readily consumed by your application. 

Log in to track your progress & complete quizzes