@amag-ch/sap_cap_common_http v4.2.0
sap_cap_common_http
Wrapper for communication with external http services
Table of Contents
Features
- Usage of destination and connectivity service build in
- Sanitizing of error objects
- Handling of APIKeys over destination service
- Autoforward 'accept-language' and 'x-correlation-id' to remote service
- Additional headers and query parameters on destinations
- Additional headers, query and data parameters on oauth based destinations
Installing
Using npm:
$ npm install @amag-ch/sap_cap_common_http
Using yarn:
$ yarn add @amag-ch/sap_cap_common_http
Configuration
Simple configuration over cds requires
{
"cds": {
"requires": {
"remote-service": {
"kind": "odata-v4",
"credentials": {
"destination": "remote-service-destination"
}
}
}
}
}
Read configuration in implementation
const http = require('@amag-ch/sap_cap_common_http')
const remoteService = await http.connect.to('remote-service')
const baseUrl = await remoteService.getBaseUrl()
const configuration = await remoteService.getConfiguration()
Implementation
const http = require('@amag-ch/sap_cap_common_http')
const remoteService = await http.connect.to('remote-service')
const response = await remoteService.get('/Ressource')
Destination Parameters
The destination service has a convention to define static headers and query parameters on destinations. Create additional properties in your destination in the SAP BTP cockpit and define their values as follows:
URL.headers.<header-key>
for headersURL.queries.<query-key>
for query parameters
Replace <header-key>
and <query-key>
with the name of your headers or query parameters and set the respective values.
For example URL.queries.language=EN
will add the query parameter language
with value EN
for every communication with the given destination
The same procedure can be used for oauth based authentication and can be defined follows:
OAuth.headers.<header-key>
for headersOAuth.queries.<query-key>
for query parametersOAuth.data.<data-key>
for data parameters
Replace <header-key>
, <query-key>
and <data-key>
with the name of your headers, query or data parameters and set the respective values.
For example, the oauth authentication against cdc as server needes as grant_type=none
. To handle this just set OAuth.data.grant_type
with value none
Same is also possible, if scopes are needed
License
27 days ago
27 days ago
4 months ago
5 months ago
10 months ago
10 months ago
10 months ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago