Why the bookshop
Every CAP tutorial starts with the bookshop, and for good reason: books, authors, and orders exercise entities, associations, compositions, and services in one small domain. Twenty minutes here teaches you the whole development loop.
Goal: a running OData V4 service with sample data, built from scratch with the
cdsCLI.
Step 1: Scaffold the project
With Node.js 20+ and the CDS development kit installed:
cds init bookshop --add sample
cd bookshop
npm install
The --add sample flag pulls in the classic bookshop domain model so you can focus on the mechanics first.
Step 2: Look at the data model
Open db/schema.cds. You'll see the essentials of CDS modeling:
entity Books {
key ID : Integer;
title : String;
author : Association to Authors;
price : Decimal;
}
Associations like author become navigable OData relationships automatically. No join code, no DTOs.
Step 3: Expose it as a service
Check srv/cat-service.cds:
service CatalogService {
entity Books as projection on my.Books;
entity Authors as projection on my.Authors;
}
Each entity in a service becomes an OData entity set. Projections let you reshape without touching the database model.
Step 4: Run it
cds watch
This starts the server with an in-memory SQLite database, loads the sample CSV data, and restarts on every file change. Open the printed URL — /catalog/Books returns your books as OData JSON.
cds watchis your development inner loop: edit CDS, save, refresh the browser. No build step.
Step 5: Add your own entity
Now make it yours. Add to db/schema.cds:
entity Reviews : cuid, managed {
book : Association to Books;
rating : Integer;
comment : String;
}
cuid adds a UUID key, managed adds created/modified audit fields. Expose it in the service, save, and watch it appear — schema, table, and OData endpoint generated for you.
Explore the generated API
With the server running, open /odata/v4/catalog/$metadata — the full machine-readable contract of your API. Then try query options directly in the browser:
/odata/v4/catalog/Books?$select=title,price&$top=5
/odata/v4/catalog/Books?$filter=price gt 20&$orderby=title
Filtering, sorting, paging, and selecting work out of the box — no handler code. This is the moment CAP clicks for most developers: the framework did all of it from your three-line service definition.
Where to go next
You now have the full loop: model → service → data → running API. Natural next steps: custom event handlers, Fiori Elements UI generation, and deploying to HANA Cloud.
Stuck on the setup? Paste your error in the comments and I'll help.