Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
artemkovalov
Advisor
Advisor
0 Kudos
382
Welcome to the March 2021 issue of the SAP Cloud SDK release highlights!

March in numbers:





    • 23 issues and support incidents received

    • 15 of those were answered or solved and closed

    • 4.8K clicks from search in Google guiding to our documentation portal

    • > 3 Mio core package downloads from NPM

    • > 3.3K downloads from Maven Central






Latest documentation updates



SAP Cloud SDK for Java 3.41.0


Quick links

OpenAPI code generator and type-safe client are now generally available


OpenAPI standard is a popular format to define RESTful APIs. Together with OData, it is one of the key API definition formats used at SAP. The SAP Cloud SDK provides convenient tooling to make the consumption of OpenAPI services easy and convenient. We provide a customized OpenAPI code generator capable of converting an OpenAPI specification into a type-safe Java client library nicely integrated with the SAP Business Technology Platform.

The code generator by SDK has extra features to influence class and method names thanks to respecting OpenAPI vendor extensions. This allows making the resulting client code much more semantic, especially in the case when Tags that are used by default are not descriptive enough or simply not suited for the naming purpose.

Here's all you need to add to your project to use the generated classes
<dependency>
<groupId>com.sap.cloud.sdk.datamodel</groupId>
<artifactId>openapi-core</artifactId>
</dependency>

You can find more details about the generator Maven plugin and its options in our guide. Give it a try and let us know your feedback.

Another way to get you hands-on is running through our self-paced TechEd exercise.

Unified API for Read requests in OData batch


If you had a chance to use read request in Batch with OData v4 API then things are going to look familiar to you. We're working towards unifying Batch API between two OData versions. We started with read requests as they were not supported in OData v2. Check the code snippet below and our documentation for more details.
BusinessPartnerService service = new DefaultBusinessPartnerService();

BusinessPartnerFluentHelper readOperationAll = service.getAllBusinessPartner().top(10);
BusinessPartnerByKeyFluentHelper readOperationByKey = service.getBusinessPartnerByKey("bupa9000");

BatchResponse response = service.batch()
.addReadOperations(readOperationAll)
.addReadOperations(readOperationByKey)
.executeRequest(destination);

List<BusinessPartner> entities = response.getReadResult(readOperationAll);
BusinessPartner entity = response.getReadResult(readOperationByKey);

Enhancements for Destinations and Requests


By default, we handle CSRF tokens for your requests implicitly. That might be sub-optimal in the development environment or when you're operating in a fully trusted environment. For these and other relevant use cases you can now suppress fetching and sending of the CSRF token with withoutCsrfToken().

We added a convenience method to configure the proxy authorizations when building a custom DefaultHttpDestination. The .proxyAuthorization("value") will send a value within the Proxy-Authorization header unless that header is already set.

Clear cache of remote BAPI functions


In certain scenarios where the signatures of BAPIs change in an SAP S/4HANA system, it might be necessary to refresh the client-side cache. You can use the newly introduced API to achieve that.
final Destination destination = DestinationAccessor.getDestination(destinationName);
try {
RemoteFunctionCache.clearCache(destination);
}
catch( final RemoteFunctionException e ) {
//deal with exception
}

final Destination destination = DestinationAccessor.getDestination(destinationName);
try {
RemoteFunctionCache.clearCache(destination, "BAPI_GET_COSTCENTER");
}
catch( final RemoteFunctionException e ) {
//deal with exception
}

How to update?


Navigate to a root folder of your project and find a pom.xml file. Bump the version of com.sap.cloud.sdk dependency to 3.41.0 similar to the XML code snippet below and you're done! Mind, because Maven Central relying on CDN it takes a bit of time for the new maven module to be distributed.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.sap.cloud.sdk</groupId>
<artifactId>sdk-bom</artifactId>
<version>3.41.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
<!-- possibly further managed dependencies ... -->
</dependencyManagement>

If for some reason your IDE hasn't fetched an updated dependency version, run mvn clean install from the command line in the root directory of your project.

SAP Cloud SDK for JavaScript


Quick links

The Currency Conversion extension library is released


Having a strong core value in the SAP Cloud SDK, we actively collaborate with other teams to provide re-usable plugins and extensions on top of the SDK's API. We're happy to announce that the open-source currency conversion library was released in March as one of such extensions.

You can use the library for the following functions:

  • Direct one-to-one conversions - from a source currency to a target currency.

  • Indirect conversions - uses inverse rates or a "reference currency".

  • Fixed-rate conversions - you have the exact currency exchange rate that you want to use in your conversion operations.

  • Non-fixed rate conversions - unlike the fixed-rate, you have a set of exchange rates. The library will pick the "best rate" from the set depending on various factors.


Here's a quick example of a direct conversion use case:
import {
SingleFixedRateConversionResult,
buildConversionParameterForFixedRate
} from '@sap-cloud-sdk/currency-conversion-models';
import { CurrencyConverter } from '@sap-cloud-sdk/currency-conversion-core';
// Initialize the Currency Conversion Library.
const currConverter = new CurrencyConverter();

try {
const result: SingleFixedRateConversionResult = currConverter.convertCurrencyWithFixedRate(
buildConversionParameterForFixedRate('INR', 'USD', '10.00', '70.23')
);
} catch (error) {
// Exception handling here
}

You'll find more valuable examples in the API documentation of the Currency conversion library.

Improved OpenAPI generator now considers vendor extensions and CSRF token


By default, we use OpenAPI tags to derive API names for classes and methods. To help with situations when tags are not the best source of names we decided to use OpenAPI vendor extensions x-sap-cloud-sdk-api-name and x-sap-cloud-sdk-operation-nameto help you make your generated client have semantic naming.

To make life easier for application development involving OpenAPI services we introduced automatic pre-fetch of CSRF token.

Use executeRaw() method to get access to a raw HTTP response


To help you with testing, debugging, and workarounds we introduced a way to access raw HTTP response and see all the related information about its status, headers, non-modified request body, and original request. You can call it on our request builder instead of a typed execute() method. This saves a lot of time because you don't have to build the test request yourself and still benefit from accessing the full request context. Check the code snippet below, and our documentation for more details.
const httpResponse: HttpResponse = MyEntity.requestBuilder()
.getAll()
.executeRaw(destination);

const status = httpResponse.status;
const responseHeaders = httpResponse.headers;
const responseBody = httpResponse.data;
const request = httpResponse.request;

How to update?


To update the version of the SAP Cloud SDK for JavaScript used in an existing project, use the command npm update in the root folder of your module. Note that this will also update other modules unless you explicitly specify which packages to update. If you want to check beforehand what will change, use npm outdated.

Additionally, you can consult NPM for more information on version history and update path.

Feedback


We hope you enjoy developing with SAP Cloud SDK! To help us further improve give your ideas and suggestions in the comments to this blog or create an issue in our GitHub repository.

All the best,

SAP Cloud SDK Team