CAP Getting Started

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Companies that run SAP S/4HANA often need a small application next to it: a partner dashboard, an expense claim form, a portal for suppliers. SAP offers a framework for building such applications, the SAP Cloud Application Programming Model, called CAP. You describe your data and your services in short text files, and CAP turns them into a running web service that speaks the OData protocol, with a database behind it, without you writing the plumbing. This page takes a newcomer from an empty folder to a working service in a few minutes: it installs the command line tools, creates a project, shows what the three folders db/, srv/ and app/ are for, starts the server, and calls it with a web request. Every command on this page was run for real in a scratch folder on 2026-11-13 and the output shown is the output it produced. The page is written against CAP Node.js 10.2 (@sap/cds 10.2.2, with the command line tools @sap/cds-dk 10.2.1, which need Node.js 22.12 or newer) and CAP Java 5.2 (Java 21 or newer, Java 25 recommended). The local steps apply on any developer machine. Running the finished application on SAP Business Technology Platform (SAP BTP) is a later step and needs an SAP BTP account, so the deployment commands are only described here, for both the Cloud Foundry and the Kyma runtime. SAP BTP is still the name used in the product documentation, and SAP now presents the SAP BTP capabilities as part of SAP Business AI Platform.

Before you read

Key terms

  • SAP Cloud Application Programming Model (CAP): SAP’s framework for building business services from models, with runtimes for Node.js and for Java.

  • Core Data Services (CDS): the text language in which CAP models data and services.

  • cds-dk: the package of command line tools, including the cds command, that creates and runs CAP projects.

  • OData: the web protocol in which a CAP service offers its data to browsers, apps and other services.

  • Generic provider: the built-in CAP code that answers requests for a service without custom code.

  • SAP BTP: SAP’s cloud platform, where a finished CAP application is deployed.

What CAP is and what you install

CAP is a framework, not a product to log in to. It consists of a modeling language (CDS), a runtime that executes the models (one for Node.js, one for Java) and a set of tools. The official Getting Started page calls the minimal setup "CAP’s cds-dk installed, which in turn requires Node.js", and treats Java and Maven, Git, and Visual Studio Code as optional additions. On macOS and Linux it suggests installing Node.js with Homebrew and the tools with npm. The tools come in one package, @sap/cds-dk, which brings the cds command.

npm i -g @sap/cds-dk
cds -v

The -g flag installs the tools for your whole user account, so the command works from every folder. The runs on this page installed the same package, version 10.2.1, into a private folder of the scratch area instead, so that nothing was installed globally, and put its bin folder on the PATH. The cds command behaves the same either way. Installing or using @sap/cds-dk and @sap/cds means accepting the SAP Developer License Agreement, version 3.2, which the packages state themselves. Asking for the versions of everything a project uses shows the baseline of this page:

$ cds version
  @sap/cds            10.2.2
  @sap/cds-compiler   7.2.1
  @sap/cds-fiori      2.3.0
  @cap-js/db-service  3.2.0
  @cap-js/sqlite      3.1.3
  Node.js             24.21.0
  npm                 11.19.0

Source: real output of cds version inside the finished scratch project (shortened: the folder paths printed in a second column are left out), described at CAP Getting Started

The run used Node.js 24.21.0, which is above the minimum of 22.12 that the package declares. The list also shows that a CAP project depends on a database package: @cap-js/sqlite is the one that provides the development database below.

Create a project: cds init

The command cds init creates a project folder with a fixed layout. Giving it only a name creates the folders, but in the version used here it does not yet choose a runtime, and it says so.

$ cds init partners

Successfully initialized CAP project without a runtime. Choose one with cds add nodejs or cds add java.
Continue with: code partners

Source: real output of cds init (CAP command line tools 10.2.1), described at CAP Getting Started

The Getting Started page shows only cds init bookshop, so a reader who follows that page with the current tools meets this message. The option list of cds help init names the two runtimes as --nodejs ("Create a CAP Node.js project") and --java ("Create a CAP Java project"), and the same list holds many features that can be added while the project is created or later with cds add, among them sqlite, hana, mta, kyma and tiny-sample. The rest of this page uses the Node.js runtime, so the project was created again, in a fresh empty folder, with that option:

$ cds init partners --nodejs
Adding facet: nodejs

Successfully initialized CAP project
Continue with: code partners

Source: real output of cds init partners --nodejs, option list from cds help init, CAP Getting Started

Then npm install fetched the two dependencies the command had written to package.json: the runtime @sap/cds and the development database package @cap-js/sqlite. The generated package.json is short.

{
  "name": "partners",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "@sap/cds": "^10"
  },
  "devDependencies": {
    "@cap-js/sqlite": "^3"
  },
  "scripts": {
    "start": "cds-serve"
  },
  "private": true
}

Source: the package.json that cds init partners --nodejs generated (CAP command line tools 10.2.1), CAP Getting Started

The SQLite package sits under devDependencies because it is the stand-in database for development: the Getting Started guide states that SQLite "isn’t meant for productive use", that it speeds up local development, and that it acts as a mock for the target database in production, SAP HANA.

The project layout

The guide describes the generated folders as app/ (UI-related content), srv/ (service-related content) and db/ (domain models and database-related content), plus a readme.md, and adds a design rule: CAP uses defaults for many things that other frameworks make you configure, so things work out of the box, and you should stick to the defaults. The three folders are the whole architecture of a small CAP application.

  • db/ holds the domain model: the entities (the tables) and their relations, and optional initial data as CSV files.

  • srv/ holds the services: the views on the domain model that the outside world is allowed to see, and the custom code for them if there is any.

  • app/ holds user interface content, such as an SAP Fiori elements or SAPUI5 application, which a later page covers.

This is the real layout of the partners project after the files of the next section were added, listed with find, without the node_modules folder that npm install created:

$ find . -not -path './node_modules*' | sort
.
./.gitignore
./.vscode
./.vscode/extensions.json
./.vscode/launch.json
./.vscode/tasks.json
./app
./db
./db/data
./db/data/example.partners-Contacts.csv
./db/data/example.partners-Partners.csv
./db/schema.cds
./eslint.config.mjs
./package-lock.json
./package.json
./readme.md
./srv
./srv/partner-service.cds

Source: real output of find in the scratch project, layout described at CAP Getting Started

The folder app/ is still empty, because the sample has no user interface. The files outside the three folders were generated by cds init: the .vscode folder with editor settings, the readme.md, the eslint.config.mjs configuration for a code checker and the package.json. Right after cds init, the folders db/ and srv/ were empty as well, and so the server had nothing to do yet; the files in them are the ones written in the next section.

Start the server: cds watch

The command cds watch starts a development server and keeps watching the project files: when a file changes, it restarts the server. The Getting Started page shows that, with no model yet, the server reports that it is waiting for content. The same happened in a fresh empty project of the same version (the port was set with the PORT environment variable, as explained below):

$ cds watch
cds serve all --with-mocks --in-memory?
( live reload enabled for browsers )

        ___________________________


    No models found in db/,srv/,app/,app/*.
    Waiting for some to arrive...

Source: real output of cds watch in an empty project, CAP Getting Started

The first line shows what cds watch does: it runs cds serve all with mocked services and an in-memory database. It looks for models in db/, srv/ and app/, which is why those folder names matter.

flowchart LR F["CDS files in db/ and srv/"] --> W["cds watch"] D["CSV files in db/data/"] --> W W --> C["Compile the model"] C --> M[("In-memory SQLite database")] C --> S["Generic provider serves OData at /odata/v4/..."] M --> S E["Edit and save a file"] -. "restart" .-> W

A teaching model: partners

The Getting Started guide teaches with a bookshop (books, authors, genres). This page follows the same pattern with a small partner directory that fits the running example of this site, Example Trading Co. (company code EX01): the business partners that Example Trading Co. buys from and sells to, and the contact people at each of them. It is a teaching model that this page defines, built in the scratch project for this page. It is not the business partner of SAP S/4HANA, which is far larger, and it is not the lab project of this site, which models expense claims (see below). The model has two entities, Partners and Contacts, and one service. This is the complete content of db/schema.cds:

using { managed, Country } from '@sap/cds/common';

namespace example.partners;

entity Partners : managed {
  key ID   : Integer;
  name     : String(80);
  role     : String(1) default 'C';  // C = customer, S = supplier
  country  : Country;
  contacts : Association to many Contacts on contacts.partner = $self;
}

entity Contacts {
  key ID   : Integer;
  partner  : Association to Partners;
  fullName : String(80);
  email    : String(120);
}

Source: the file db/schema.cds of the scratch project, written in the style of The Bookshop Sample

A few lines need explaining for a newcomer. The line entity Partners : managed says that the entity is built from a reusable piece called managed, taken from the CAP library @sap/cds/common, which adds columns that record who created and last changed each row and when; they appear in the output below. The line country : Country uses another reusable type from the same library, a reference to a table of country codes. The line starting with contacts is an association: a link from one partner to many contacts, which the part after on ties to the field partner of Contacts. The type Association to Partners inside Contacts is the other end of that link. The text after the two slashes is a comment.

A service is a window onto the model. This is the complete srv/partner-service.cds:

using { example.partners as my } from '../db/schema';

service PartnerService {
  @readonly entity Partners as projection on my.Partners;
  @readonly entity Contacts as projection on my.Contacts;
}

Source: the file srv/partner-service.cds of the scratch project, in the style of the services of The Bookshop Sample

The keyword projection on makes each service entity a view of an entity of the model, and the annotation @readonly turns off writing, so this service can only be read. The guide explains the thought behind this: services are the interface of an application to its consumers and also its facade, which restricts access to the inner domain data, so a service is designed for the consumer that it serves.

Initial data is placed in CSV files in db/data, named after the namespace and the entity, with a header line of column names. The guide shows this for the bookshop and mentions that cds add data can generate the headers. The files of this project were written by hand. This is db/data/example.partners-Partners.csv:

ID,name,role,country_code
1001,Example Trading Co.,C,US
1002,Example Paper Supply,S,DE
1003,Example Harbor Logistics,S,ES

and this is db/data/example.partners-Contacts.csv:

ID,partner_ID,fullName,email
1,1001,Ada Example,ada@example.com
2,1002,Bruno Beispiel,bruno@example.com
3,1002,Carla Muestra,carla@example.com

Source: the files db/data/example.partners-Partners.csv and db/data/example.partners-Contacts.csv of the scratch project, file naming described at The Bookshop Sample

All names and addresses are made up. The column country_code is the foreign key that the association country stands for, and partner_ID is the one behind partner; the next section shows that the compiler creates exactly those columns.

The server answers: cds watch with a model

The scratch project was started with the port set to 4116 so that it does not clash with another server on the machine. The default port of CAP is 4004, which is the address that the Getting Started page uses. The command was PORT=4116 cds watch. As soon as the three files existed, the watcher reloaded and printed this (the banner is left out):

[cds] - loaded model from 3 file(s):

  srv/partner-service.cds
  db/schema.cds
  node_modules/@sap/cds/common.cds

[cds] - using bindings from: { registry: '~/.cds/services' }
[cds] - connect to db > sqlite { url: ':memory:' }
  > init from db/data/example.partners-Partners.csv
  > init from db/data/example.partners-Contacts.csv
/> successfully deployed to in-memory database.

[cds] - using auth strategy { kind: 'mocked' }
[cds] - serving PartnerService {
  at: [ '/odata/v4/partner' ],
  decl: 'srv/partner-service.cds:3'
}
[cds] - server listening on { url: 'http://localhost:4116' }
[cds] - server v10.2.2 launched in 185 ms

Source: real output of PORT=4116 cds watch (shortened: the banner is left out), shape of the output described at CAP Getting Started

Reading the output from the top gives the whole start-up story. Three model files were loaded, the third being the CAP library that provides managed and Country. The database is SQLite in memory (:memory:), so its content is created again at every restart, and the two CSV files filled it. The authentication strategy is mocked: during development CAP lets requests through as a stand-in user, which the data below confirms (anonymous). The service PartnerService was mounted at /odata/v4/partner: the service name without its Service suffix, in lower case, under the OData V4 path. The line of the Getting Started page for the tiny sample, serving CatalogService at /odata/v4/catalog, shows the same rule.

Call the service

The server answers ordinary web requests, so a browser or curl is enough. The first request asks for the whole partner collection and shows the response headers:

curl -s -i "http://localhost:4116/odata/v4/partner/Partners"
HTTP/1.1 200 OK
OData-Version: 4.0
Content-Type: application/json; charset=utf-8; ieee754compatible=true
Content-Length: 649

Source: real response of the request above (shortened: the date, correlation and connection headers and the JSON body are left out; the body is shown in the next request), URL pattern from CAP Getting Started

The header OData-Version: 4.0 shows that the service speaks OData V4. A single record, pretty-printed with python3 -m json.tool for readability, shows the shape of the answer and the columns that managed added:

curl -s "http://localhost:4116/odata/v4/partner/Partners?\$top=1"
{
    "@odata.context": "$metadata#Partners",
    "value": [
        {
            "createdAt": "2026-11-13T14:14:38.686Z",
            "createdBy": "anonymous",
            "modifiedAt": "2026-11-13T14:14:38.686Z",
            "modifiedBy": "anonymous",
            "ID": 1001,
            "name": "Example Trading Co.",
            "role": "C",
            "country_code": "US"
        }
    ]
}

Source: real response of the request above, URL pattern from CAP Getting Started

The URL used the OData system query option $top. The Getting Started guide uses the same style of options, such as $select and $expand, in its bookshop requests. The next request keeps only the suppliers (role S), selects three fields and sorts by name. The quotes and the dollar signs are written for a Unix shell, where the filter text is written in a form that curl sends as is (the spaces become %20):

curl -s "http://localhost:4116/odata/v4/partner/Partners?\$select=ID,name,country_code&\$filter=role%20eq%20'S'&\$orderby=name"
{"@odata.context":"$metadata#Partners","value":[{"ID":1003,"name":"Example Harbor Logistics","country_code":"ES"},{"ID":1002,"name":"Example Paper Supply","country_code":"DE"}]}

Source: real response of the request above, option style from The Bookshop Sample

The partner with the role C, Example Trading Co., is left out, and the two suppliers are in alphabetical order. The association contacts can be followed in the same request with $expand, which nests the contacts of a partner inside it:

curl -s "http://localhost:4116/odata/v4/partner/Partners?\$select=name&\$expand=contacts(\$select=fullName)&\$filter=ID%20eq%201002"
{"@odata.context":"$metadata#Partners","value":[{"name":"Example Paper Supply","contacts":[{"fullName":"Bruno Beispiel","ID":2},{"fullName":"Carla Muestra","ID":3}],"ID":1002}]}

Source: real response of the request above, $expand style from The Bookshop Sample

The two contacts of Example Paper Supply came back inside the partner. Nothing in the project mentions OData requests or SQL: the generic provider translated the request into a database query, which is the point the guide makes under "Served automatically by generic providers".

The service root and the service description document are also available. The request for the root lists the entity sets:

curl -s "http://localhost:4116/odata/v4/partner/"
{"@odata.context":"$metadata","@odata.metadataEtag":"W/\"FNBgBOJVyy7YA/ELrs4ywMFGBBO3iPsQV1V89bD0Hso=\"","value":[{"name":"Partners","url":"Partners"},{"name":"Countries","url":"Countries"},{"name":"Countries_texts","url":"Countries_texts"},{"name":"Contacts","url":"Contacts"}]}

Source: real response of the request above, CAP Getting Started

Besides the two entities that the service declares, the root also lists Countries and Countries_texts. They belong to the code list of country codes behind the type Country from @sap/cds/common; the service offers them because the model refers to that type, and they are empty here because the project has no data for them. The request for $metadata returns the machine-readable description of the service (an XML document whose first element is edmx:Edmx, version 4.0), which front-end tools read to learn what the service offers.

The service was declared @readonly, so a write request must fail. The answer shows that CAP enforces the annotation:

curl -s -i -X POST -H 'Content-Type: application/json' -d '{"ID":9,"name":"x"}' http://localhost:4116/odata/v4/partner/Partners
HTTP/1.1 405 Method Not Allowed
{"error":{"message":"Entity \"PartnerService.Partners\" is read-only","code":"ENTITY_IS_READ_ONLY","@Common.numericSeverity":4}}

Source: real response of the request above (shortened: only the status line and the body are shown), annotation described at The Bookshop Sample

What happened underneath

The in-memory database was created from the model. The guide shows how to look at it without starting the server: cds compile db/schema.cds --to sql prints the SQL that CAP derives from the CDS file. The beginning of the real output for the partners model follows. Compare it with the model: managed became four columns, the association country became the foreign key country_code, the association partner became partner_ID, and the declared default 'C' became a SQL default. The association contacts has no column, because it is only a way to navigate, and not data.

CREATE TABLE example_partners_Partners (
  createdAt TIMESTAMP_TEXT,
  createdBy NVARCHAR(255),
  modifiedAt TIMESTAMP_TEXT,
  modifiedBy NVARCHAR(255),
  ID INTEGER NOT NULL,
  name NVARCHAR(80),
  role NVARCHAR(1) DEFAULT 'C',
  country_code NVARCHAR(3),
  PRIMARY KEY(ID)
);

CREATE TABLE example_partners_Contacts (
  ID INTEGER NOT NULL,
  partner_ID INTEGER,
  fullName NVARCHAR(80),
  email NVARCHAR(120),
  PRIMARY KEY(ID)
);

Source: real output of cds compile db/schema.cds --to sql (shortened: the tables for the country code list and a localized view that the compiler also printed are left out), The Bookshop Sample

The table names show the namespace joined to the entity name with underscores (example_partners_Partners). The guide describes SQLite as a development stand-in for SAP HANA, the target database in production, so the same model is meant to be deployed to either one.

The lab project of this site

The project built above is a teaching model for this page. The lab of this site contains a second, finished project in the repository folder modules/ROOT/examples/sap-lab/expenses, which models the expense claims of Example Trading Co. and is the project that the SAP guides use. It has the same layout as above: db/schema.cds defines an entity Claims (built from the library pieces cuid and managed, with the fields title, status and amount), srv/expense-service.cds projects it as ExpenseService, with the annotation @odata.draft.enabled for draft editing, srv/expense-service.js holds a custom handler that rejects a negative amount, app/annotations.cds holds user interface annotations, and http/claims.http holds request files like those of this page. Its package.json pins the exact versions used on this page, so npm install and npm run watch in that folder reproduce the setup. Like the partners model, it is a teaching model built with CAP. It is not SAP S/4HANA and does not reproduce its screens.

Growing the project and running it on SAP BTP

The guide’s slogan is "Grow as You Go": a project starts minimal, and cds add adds features when they are needed. It lists, among others, cds add data (initial data), cds add hana (SAP HANA support), cds add xsuaa (authentication with the XSUAA service), cds add mta (Cloud Foundry deployment with an mta.yaml file), cds add kyma (a Kyma setup) and cds add github-actions, and it offers cds up to build and deploy in one step, with --to cf for Cloud Foundry and --to k8s for Kubernetes. The option list of cds help init says that mta is "Cloud Foundry deployment using mta.yaml" and kyma is "Kyma deployment using Helm charts".

Requires an SAP BTP account; not run here:

cds add hana,xsuaa,mta
cds up --to cf

Source: command names from CAP Getting Started and cds help init (CAP command line tools 10.2.1); the combination and the target are written from those names and were not run because they need an SAP BTP account

The development setup of this page therefore differs from production in three planned ways. SQLite becomes SAP HANA (cds add hana), the mocked users become real ones (cds add xsuaa, which a later page on security covers), and the project is packaged and deployed to Cloud Foundry (cds add mta) or Kyma (cds add kyma). The db/ and srv/ models are the part that the guide’s "Grow as You Go" approach keeps in place while these facets are added. Cloud Foundry and Kyma are the two targets named by those options, and facts about either of them apply to a CAP application only once it is deployed there.

CAP Java in short

CAP also has a Java runtime. The Java Getting Started page lists the tools as the CDS tools from the central guide, a Java VM ("Java 21 is the minimum requirement, but we recommend using Java 25"), and Apache Maven (at least 3.9.14). A project can be created with a Maven archetype or with the same tools as above:

Requires Java and Maven; not run here:

cds init <PROJECT-ROOT> --java

The generated Java project has a db/ folder for the domain model and a srv/ folder for the service definitions and the Java code, so the CDS models of this page apply to both runtimes. The Java page also states that CAP Java supports SQLite databases for local development and SAP HANA as a productive database, which matches the Node.js setup above.

Summary

  • CAP builds business services from short CDS models: install @sap/cds-dk with npm i -g @sap/cds-dk, which brings the cds command, and create a project with cds init <name> --nodejs (or --java).

  • A project has three folders: db/ for the domain model and CSV data, srv/ for services and app/ for user interfaces.

  • cds watch runs the project with an in-memory SQLite database and the generic provider, restarts on every file change, and serves OData V4 at /odata/v4/<service>; the default port is 4004.

  • The partners teaching model needed two small CDS files and two CSV files, and answered $select, $filter, $orderby and $expand requests with real data and no custom code.

  • SQLite, mocked users and the local server are for development; SAP HANA, XSUAA and a Cloud Foundry or Kyma deployment on SAP BTP are added with cds add and cds up, and need an SAP BTP account.

Try it

To do this by hand, follow the guide Your First CAP Service: it creates a CAP project with an entity and a service and calls the service in the browser.