Exercise 4: Multiple Services Configuration

This exercise shows how to configure multiple OData services representing a microservices architecture where different domains are handled by separate services.

4.1 Understanding the Real Services Architecture

In this exercise, you'll configure multiple OData services based on the actual CAP services running on http://localhost:4004 . We have two services available:

  • BookshopService : /bookshop - Main service with Books, Chapters, and Reviews entities
  • ReviewsService : /reviews - Service for review management

This represents a microservices setup where different domains are handled by separate services.

4.2 Setup Multiple Services Configuration

1. Create directory structure for the reviews service:

mkdir -p webapp/localService/reviewService
mkdir -p webapp/localService/reviewService/data

2. Copy the actual reviews service metadata:

Since we're using a real CAP service, we can copy the metadata directly from the running service:

Create webapp/localService/reviewService/metadata.xml by copying the metadata from http://localhost:4004/reviews/$metadata .

3. Create review data ( webapp/localService/reviewService/data/Reviews.json ):

ex4/webapp/localService/reviewService/data/Reviews.json View on GitHub ↗
[
  {
    "ID": "23a6dd83-a75d-41c5-ad57-2314bc67ed2b",
    "reviewer": "John Doe",
    "rating": 5,
    "comment": "A timeless classic that never gets old!",
    "book_ID": "3afb35fa-e2c9-40d0-8e22-90e96ead9944",
    "createdAt": "2024-01-15T10:30:00Z",
    "IsActiveEntity": true,
    "HasActiveEntity": false,
    "HasDraftEntity": false
  },
  {
    "ID": "34b7ee94-f86c-52e6-be58-3425cd78fe3c",
    "reviewer": "Jane Smith",
    "rating": 4,
    "comment": "Great character development and storytelling.",
    "book_ID": "7c8f2a1b-d4e5-4c6a-9b7e-1f3a5c8d2e4b",
    "createdAt": "2024-01-20T14:45:00Z",
    "IsActiveEntity": true,
    "HasActiveEntity": false,
    "HasDraftEntity": false
  },
  {
    "ID": "45c8ff05-097d-63f7-cf69-4536de89df5d",
    "reviewer": "Book Lover",
    "rating": 3,
    "comment": "Decent read, but could be better paced.",
    "book_ID": "3afb35fa-e2c9-40d0-8e22-90e96ead9944",
    "createdAt": "2024-02-01T09:15:00Z",
    "IsActiveEntity": true,
    "HasActiveEntity": false,
    "HasDraftEntity": false
  }
]

4. Create Books reference data ( webapp/localService/reviewService/data/Books.json ):

ex4/webapp/localService/reviewService/data/Books.json View on GitHub ↗
[
  {
    "ID": "3afb35fa-e2c9-40d0-8e22-90e96ead9944",
    "title": "The Great Gatsby",
    "author": "F. Scott Fitzgerald",
    "IsActiveEntity": true,
    "HasActiveEntity": false,
    "HasDraftEntity": false
  },
  {
    "ID": "7c8f2a1b-d4e5-4c6a-9b7e-1f3a5c8d2e4b",
    "title": "To Kill a Mockingbird",
    "author": "Harper Lee",
    "IsActiveEntity": true,
    "HasActiveEntity": false,
    "HasDraftEntity": false
  }
]

5. Update ui5-mock.yaml to include both services:

ex4/ui5-mock.yaml View on GitHub ↗
server:
  customMiddleware:
    - name: sap-fe-mockserver
      beforeMiddleware: csp
      configuration:
        mountPath: /
        debug: true
        watch: true
        services:
          # Main bookshop service
          - urlPath: /bookshop
            alias: bookshop
            metadataPath: ./webapp/localService/mainService/metadata.xml
            mockdataPath: ./webapp/localService/mainService/data
            generateMockData: false
          # Reviews service
          - urlPath: /reviews
            alias: reviews
            metadataPath: ./webapp/localService/reviewService/metadata.xml
            mockdataPath: ./webapp/localService/reviewService/data
            generateMockData: false
        annotations: []
Result: Multiple services configuration enables testing complex applications with microservices architecture.

4.3 Start the Application

# from folder ex4
npm run start-mock
# or from root folder
npm run start:ex4

Now you should see in the List Report the Books from the mainService defined in the /webapp/localService/mainService/data folder.

To see the data from the reviewService you can request the data by simply opening the URLs:

Now you could include the reviews in the app in any way you want.

Next Steps

Exercise 5 will show how to implement cross-service communication where operations in one service trigger actions in another service, simulating real microservices integration patterns.