4.2.0 • Published 27 days ago

@amag-ch/sap_cap_common_http v4.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
27 days ago

sap_cap_common_http

npm version npm downloads

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 headers
  • URL.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 headers
  • OAuth.queries.<query-key> for query parameters
  • OAuth.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

MIT

2.9.0

27 days ago

3.3.0

27 days ago

4.2.0

4 months ago

4.1.0

5 months ago

3.2.1

10 months ago

3.2.0

10 months ago

4.0.1

10 months ago

2.7.0

2 years ago

2.6.1

2 years ago

2.6.0

2 years ago

2.8.0

2 years ago

3.1.0

2 years ago

2.5.0

2 years ago

2.4.1

2 years ago

2.4.0

2 years ago

2.3.0

3 years ago

2.0.3

3 years ago

2.2.0

3 years ago

2.1.1

3 years ago

2.0.2

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago