SAP Cloud CAP Samples

repository·main·Indexed 20 days ago

https://github.com/sap-archive/cloud-cap-samples

A monorepo (@capire/samples v3.0.0) containing several demonstration projects for the SAP Cloud Application Programming Model (CAP). It includes the Bookshop Getting Started sample for domain modeling and custom logic, a dynamic logging sample for cds.log, and the Reviews Service for modular microservices patterns. Additional packages include @capire/common for library extensions, @capire/orders for compositions, and @capire/bookstore, a composite application integrating Vue.js and SAP Fiori elements.

Tokens
3.7K
Snippets
11
Records
23
Agent score
69%

What's inside cloud-cap-samples

  1. Extend @sap/cds/common with @capire/common

    main

    The @capire/common package demonstrates how to extend the standard @sap/cds/common library. It is a useful reference for:

    • Building extension packages: Creating reusable domain model extensions.
    • Providing reuse packages: Sharing content across different CAP projects.
    • Verticalization: Adapting common models to specific business needs.
    • Using Aspects: Implementing CDS Aspects to add reusable properties to entities.
  2. Run the Reviews Service and Fiori app as separate services

    main

    If you need to run the backend reviews service and the frontend Fiori application independently, follow these steps using two separate terminal windows:

    1. Start the reviews service: In the first terminal, run the standalone service command.
    2. Start the Fiori app: In the second terminal, run the Fiori application command.

    This approach is useful for debugging the service independently of the UI or simulating a distributed environment.

    # Terminal 1: Start the reviews service
    npm run reviews-service
    
    # Terminal 2: Start the fiori app
    npm run fiori
  3. Explore Bookshop Sample implementation details

    main

    The Bookshop sample demonstrates various CAP (Cloud Application Programming Model) development tasks. You can map the following sample files and folders to their corresponding CAP concepts:

    • Project Structure: The root directory ./.
    • Domain Modeling: Defined in ./db/schema.cds using CDS.
    • Service Definitions: Defined in ./srv/*.cds (includes single-purposed services).
    • Custom Logic: Implemented in ./srv/*.js.
    • Database Data: Initial data provided in ./db/data/*.csv.
    • Service Reuse/Composition: Managed via ./index.cds.
    • Testing: Located in the ./test directory.
  4. Build modular services with @capire/reviews

    main

    The @capire/reviews package showcases how to build a modular service for managing product reviews. It is ideal for learning how to handle complex service interactions, including:

    • Service Consumption: Consuming other services both synchronously and asynchronously.
    • Request Handling: Serving requests synchronously.
    • Event-Driven Architecture: Emitting events asynchronously.
    • Microservices Patterns: Implementing 'Grow as you go' strategies, including mocking app services, running service meshes, and late-cut microservices.
    • Service Governance: Implementing managed data, input validations, and authorization.
  5. Implement orders management with @capire/orders

    main

    The @capire/orders package is a standalone service designed to demonstrate advanced domain modeling and data serving techniques:

    • Compositions: Using CDS Compositions to define parent-child relationships in domain models.
    • Deeply Nested Documents: Serving structured, deeply nested data through generic providers.
  6. Build composite applications with @capire/bookstore

    main

    The @capire/bookstore package is a composite application that demonstrates how to reuse and combine multiple specialized packages. It integrates:

    • @capire/bookshop
    • @capire/reviews
    • @capire/orders
    • @capire/common
    • @capire/data-viewer

    It also demonstrates how to serve various UI technologies, including Vue.js apps (from bookshop, reviews, and data-viewer) and SAP Fiori elements (from orders).

    For developers building Fiori applications, this sample introduces:

    • OData Annotations: Defining UI metadata directly in .cds files.
    • Fiori Draft: Implementing draft handling for better user experience.
    • Value Helps: Providing assistance for data entry.
    • Local Development: Serving SAP Fiori apps in a local environment.
  7. Install and use the all-in-one monorepo

    main

    The repository is structured as an all-in-one monorepo where each subdirectory is a standard npm package. Some packages have local dependencies on other samples within the repository.

    To set up the entire environment and link all local packages, run npm install from the root directory. This will populate the local node_modules and configure local links, allowing the individual sample packages to resolve their dependencies from the local subfolders instead of an external registry.

    npm install
  8. Explore the @capire/bookshop Getting Started sample

    main

    The @capire/bookshop package serves as a foundational guide for getting started with the SAP Cloud Application Programming Model (CAP). It covers the core lifecycle of a CAP project, including:

    • Project Setup & Layouts: Initializing the project structure.
    • Domain Modeling: Defining data models using CDS.
    • Defining Services: Exposing models via service definitions.
    • Generic Providers: Using standard CAP capabilities to serve data.
    • Custom Logic: Implementing service handlers and custom business logic.
    • Databases: Working with underlying database technologies.