Service Bindings
Service bindings configure connectivity to required services. CAP runtimes use them to connect to these services at runtime, using credentials injected from the binding environment, such as url, and authentication details.
Declaring Required Services
Required services are declared via cds.requires configuration in CAP Node.js. Such configurations are typically placed in an application's package.json file, for example like this in case of @capire/bookstore/package.json :
"cds": {
"requires": {
"ReviewsService": { "kind": "odata" },
"OrdersService": { "kind": "odata" }
}
}The key names under cds.requires (here: ReviewsService and OrdersService) correspond to the names of the required services, used when calling cds.connect.to(<service>) in service implementations, for example:
const ReviewsService = await cds.connect.to ('ReviewsService')Configurations for required services can also be provided in a plug & play manner by CAP plugins. For example, the @capire/xtravels sample application automatically requires two services, provided by the CAP plugins @capire/s4 and @capire/xflights.
Learn more about that in the CAP-level Service Integration guide.
Configuration Properties
| Property | Description |
|---|---|
kind | (mandatory) protocol to use -> one of odata, rest, or hcql |
impl | custom service implementation to use |
model | a model to load automatically |
service | name of the service definition (default: same as key) |
credentials | usually filled from binding environment, as outlined below |
- Find detailed documentation about these properties in the CAP Node.js documentation.
Inspect using cds env
You can inspect the effective configurations of declared required services using the cds env command, including those from CAP plugins. For example, running this command in the @capire/xtravels project yields the output below:
cds env requires'sap.capire.flights.data': {
kind: '*'
},'sap.capire.s4.business-partner': {
kind: 'odata-v2',
impl: '@sap/cds/srv/remote-service.js',
service: 'API_BUSINESS_PARTNER'
},Add the -b flag to see the full configurations including credentials injected from the binding environment (if any). For example, run these commands from the xtravels project root in three different terminals:
cds mock apis/capire/xflights.cdscds mock apis/capire/s4.cdscds env requires -b'sap.capire.flights.data': {
kind: 'hcql',
impl: '@sap/cds/srv/remote-service.js',
credentials: { url: 'http://localhost:51441/hcql/data' }
},'sap.capire.s4.business-partner': {
kind: 'odata-v2',
impl: '@sap/cds/srv/remote-service.js',
service: 'API_BUSINESS_PARTNER',
credentials: { url: 'http://localhost:51438/odata/v4/business-partner' }
},