SAP UI5 provides a rich user interface layer for SAP applications, while SAP CAP serves as the robust backend for business logic and persistence. Integrating the two allows developers to build enterprise-ready applications with a seamless, full-stack experience.
This guide walks through connecting UI5 to CAP services, consuming OData endpoints, handling authentication, and best practices for deployment.
Why UI5 + CAP Integration Matters
- UI5 provides responsive, Fiori-compliant UI components
- CAP exposes OData services automatically from CDS models
- Standardized API consumption ensures scalability and maintainability
- Enables event-driven, real-time UI updates using CAP messaging
Exposing CAP Services to UI5
CAP automatically exposes OData services. For example, in srv/catalog-service.cds:
service CatalogService {
entity Products as projection on db.Products;
entity Orders as projection on db.Orders;
}
CAP generates endpoints:
/catalog/Products
/catalog/Orders
/catalog/$metadata
UI5 apps consume these endpoints via OData models.
Consuming OData in UI5
Step 1: Define OData Model in manifest.json
"sap.ui5": {
"models": {
"": {
"dataSource": "catalogOData",
"preload": true,
"settings": {
"defaultBindingMode": "TwoWay"
}
}
},
"dataSources": {
"catalogOData": {
"uri": "/catalog/",
"type": "OData",
"settings": {
"odataVersion": "4.0"
}
}
}
}
Step 2: Bind Data to UI5 Controls
this.getView().setModel(this.getOwnerComponent().getModel());
this.byId("productTable").bindItems({
path: "/Products",
template: new sap.m.ColumnListItem({
cells: [
new sap.m.Text({ text: "{name}" }),
new sap.m.Text({ text: "{price}" })
]
})
});
Handling Authentication
UI5 interacts with CAP backend securely via XSUAA:
- JWT token issued by XSUAA
- Included automatically in requests if app runs on BTP
- Local testing uses mock authentication or
@sap/cds-dk
Example for local authentication:
$.ajax({
url: "/catalog/Products",
headers: { "Authorization": "Bearer <token>" }
});
Advanced Data Handling
- Use
$filter,$select,$expandin OData calls to optimize performance
Example:
this.byId("productTable").bindItems({
path: "/Products?$filter=price gt 100",
template: new sap.m.ColumnListItem({ ... })
});
- Use
TwoWaybinding to automatically reflect CAP service updates in UI5 - Handle CAP events to update UI dynamically
Deploying UI5 with CAP
Option 1: Embedded in CAP Project
- Place UI5
webappfolder inside CAP project - CAP serves UI5 app via static route
cds watch
UI5 accessible at http://localhost:4004/webapp.
Option 2: Separate Deployment
- Deploy UI5 to SAP BTP HTML5 repository
- Configure destination to CAP OData service
- Supports decoupled front-end/back-end deployment
Multi-Tenant Considerations
- CAP automatically handles tenant context
- Ensure UI5 requests include tenant-aware headers or tokens
- Use multi-tenant features in CAP to isolate data per customer
Real-World Example
- Develop CAP backend with Orders, Products, Customers
- Expose OData endpoints from CDS projections
- Build UI5 Fiori app consuming
/Productsand/Orders - Bind tables and forms to OData models
- Deploy CAP to Cloud Foundry, UI5 to HTML5 repository
- Enable authentication using XSUAA and test multi-tenant access
Best Practices
- Keep UI5 and CAP loosely coupled via OData services
- Use projections to expose only required fields
- Secure backend with RBAC and XSUAA
- Leverage two-way binding for reactive UI
- Cache OData responses when appropriate
- Test locally before deploying to BTP
Conclusion
Integrating SAP UI5 with CAP backend ensures a robust, scalable, and secure full-stack application. CAP’s OData services, combined with UI5’s responsive front-end components, enable enterprise-grade applications that are easy to develop, maintain, and deploy on SAP BTP.

WhatsApp us