Fiori on CAP Part 3: Building and Deploying a Fiori Elements App on CAP
Free sample lesson · open to everyone
Build a full-stack app with CAP and Fiori elements on BTP: domain model, service with annotations and drafts, authorization with @requires and @restrict, the app module in the same MTA, and deployment with Work Zone.
In this lessonShow sectionsHide sections
Visual overview
The situation: a real project scenario
A CAP prototype went to QA without authorization annotations. Testers with any BTP login could edit all records. Adding @requires and @restrict with role collections, and tests that call the service with different roles, closed the gap before production.
Explanation
This final integration part builds the same kind of app on CAP and BTP.
In a CAP project, domain entities are defined in db/*.cds, and services in srv/*.cds expose projections over them. UI annotations and @odata.draft.enabled are added directly on the service entities, and any custom logic for validations and actions is written in handlers, in either Node.js or Java. CAP models data in CDS, exposes services with annotations, and handles drafts and authorizations declaratively, rather than through hand-written plumbing.
Authorization is handled through @requires on services and @restrict on entities, which define which roles can do what and under what conditions — for example, read access for viewers but write access only for owners. Those roles map to role collections in BTP through xs-security.json. Leaving a service without these authorization annotations exposes its data to any authenticated user, so they're not optional in a real deployment.
The Fiori elements app itself is generated into the app folder using SAP Fiori tools, and includes xs-app.json routes pointing to the CAP service. Local development typically uses cds watch with sample data and mocked authentication, so the UI can be built before the real back end is wired up.
For packaging and deployment, the MTA bundles the CAP service module, the HANA deployer for the database, the UI module destined for the HTML5 repository, and service instances such as XSUAA and destinations. Deploying the MTA creates everything in the subaccount at once, and Work Zone then shows the app to its users.
Operationally, this setup calls for separate subaccounts per stage, CI/CD for the MTA, and ongoing monitoring of the CAP app. Because updates to the model and the UI move together in one artifact, the two stay consistent with each other rather than drifting apart.
In practice, this means creating a CAP project with an entity and a draft-enabled service, adding UI annotations and @restrict rules, generating the Fiori app into the app folder, and then building and deploying the MTA and opening it in Work Zone — ending with a CAP-based Fiori elements app running on BTP with drafts and role-based authorization in place.
How the SAP process fits together
SAP PROCESS EXPLORER · Fiori: from service to user
ERPClimb.comFiori on RAP and CAP Services — process breakdown
Topic-specific conceptual flow: how key objects and decisions fit together. SAP configurations and exceptional cases can follow different paths.
Selected process stage
Model
RAP business objects or CAP services provide data
Representative SAP learning flow, not a guarantee of system runtime sequence in every scenario.
Watch out
Common mistakes
Deploying a CAP service to any shared environment (even QA) without @requires and @restrict authorization annotations is a serious and surprisingly common gap, especially in prototypes that 'just need to demo something quickly' — without them, anyone with a valid platform login can read and write every record, which is exactly what happened in this lesson's example.
Deploying the UI (Fiori elements app) and the CAP service as separate artifacts that can drift out of sync in version or configuration, rather than packaging them together in one MTA, creates a class of bugs where the UI expects an entity shape or annotation the currently-deployed service version doesn't have (or vice versa), and the mismatch is hard to reproduce outside production.
Testing only with a mocked administrator-equivalent user during development hides exactly the authorization gaps that matter most, since an admin role typically bypasses the restrictions real end users will hit — the first real multi-role test often happens, by default, in UAT or production.
Placing UI annotations directly on database/core entities instead of on service projections means every service that exposes that entity inherits UI directives meant for one specific app, which breaks the moment a second app needs a different layout for the same data.
Do this
Best practices
Define @requires and @restrict authorization annotations on every CAP service as a non-negotiable step before any shared deployment, including QA and demo environments — not an afterthought added before go-live.
Package the service, database, and UI modules together in one MTA so they are built, versioned, and deployed as a single consistent unit, eliminating the class of bugs caused by UI and service versions drifting apart.
Write and run tests that call the service as different role collections (not just an admin-equivalent user), specifically to confirm restricted users are actually restricted, not just that authorized users can do their job.
Put UI-facing annotations on service projections (not on the underlying database entities), so different services exposing the same core data can present different Fiori elements layouts without conflict.
In the interview
Interview angle
A pointed interview question is: 'You've built a working CAP + Fiori elements prototype — what's missing before it can go to a shared test environment?' The strong answer leads with authorization: @requires/@restrict annotations and role-based testing, explaining that a prototype which 'just works' for its builder (usually with elevated access) can be wide open for everyone else.
A senior-level answer also mentions packaging service, database, and UI in a single MTA and placing UI annotations on service projections rather than core entities, showing awareness of both the security and the maintainability dimensions of a CAP-based Fiori project.
Practice this lesson
Original educational case studies for SAP consultants, not official SAP certification exam questions. Verify product edition and implementation details against the current SAP documentation.
Quick check
0 of 3 questions attempted
Question 1 of 3
Which CAP annotations define who can access services and entities?
Question 2 of 3
What happens if a CAP service has no authorization annotations?
Question 3 of 3
How are the CAP service, database artefacts and Fiori UI typically deployed together?
Practise this in an interview
Answer in your own words and get instant feedback, the way an interviewer would judge it.
1How do you build and secure a Fiori elements app on SAP CAP for BTP?
Was this lesson helpful?
Keep exploring
More lessons in this topic
Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.