Skip to content

Commit 239f0c5

Browse files
cds export (#2275)
Co-authored-by: René Jeglinsky <rene.jeglinsky@sap.com>
1 parent 3560931 commit 239f0c5

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

tools/assets/cds-export.png

69.7 KB
Loading

tools/cds-cli.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,70 @@ To customize the diagram layout, use these settings in the _Cds > Preview_ categ
468468
- [Diagram: Namespaces](vscode://settings/cds.preview.diagram.namespaces)
469469
- [Diagram: Queries](vscode://settings/cds.preview.diagram.queries)
470470

471+
472+
## cds export <Beta />
473+
474+
With `cds export` you create an API client package to be used
475+
for data exchange via CAP-level Service integration ("Calesi").
476+
477+
Define data provider services in your CDS model that serve as an interface to your data, placing each data provider service in a separate file.
478+
479+
For the [xflights](https://github.com/capire/xflights) sample app,
480+
an API that provides information about flights, airports, and airlines
481+
could look like this:
482+
483+
::: code-group
484+
485+
```cds [srv/data-service.cds]
486+
using { sap.capire.flights as my } from '../db/schema';
487+
488+
@data.product @hcql @rest @odata
489+
service sap.capire.flights.data {
490+
@readonly entity Flights as projection on my.Flights;
491+
@readonly entity Airlines as projection on my.Airlines;
492+
@readonly entity Airports as projection on my.Airports;
493+
}
494+
```
495+
496+
:::
497+
498+
Then create an API client package for this service:
499+
500+
```sh
501+
cds export srv/data-service.cds
502+
```
503+
504+
The command generates the API client package into a new folder _apis/data-service_.
505+
506+
![The screenshot is described in the accompanying text.](assets/cds-export.png) {style="filter: drop-shadow(0 2px 5px rgba(0,0,0,.40));"}
507+
508+
The `service.csn` contains only the interface defined in the service, removing the query part of the entities and all the underlying model.
509+
In addition, there are i18n bundles with the localized metadata relevant
510+
for the interface, and a _data_ folder with test data
511+
that exactly matches the structure of the entities in the API.
512+
513+
`cds export` also adds a _package.json_. The package name combines the application name (from the main _package.json_) with the file name of the data service. In our example, this results in `@capire/xflights-data-service`.
514+
You can change this name as appropriate.
515+
516+
You can then publish the generated package, for example, via `npm publish`.
517+
518+
To consume the API in another CAP application:
519+
1. Import the API package with `npm add`
520+
2. Define consumption views on the imported entities
521+
3. Use them in your model as if they were local entities
522+
4. Add custom code to access the data in the provider app via any of the offered protocols
523+
524+
Have a look at the [xtravels](https://github.com/capire/xtravels) sample app for an
525+
example of using an API client package.
526+
527+
:::warning Do not use EDMX to exchange API information
528+
Prefer exporting and importing API packages via `cds export` and `npm add`.
529+
**Do not use** EDMX (or OpenAPI) as intermediate format for exchanging API information
530+
between CAP applications, as you might loose information.
531+
:::
532+
533+
534+
471535
## cds watch
472536

473537
Use `cds watch` to watch for changed files, restarting your Node.js server.

0 commit comments

Comments
 (0)