lemaiwo / cds-plugin-handlers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CDS-PLUGIN-HANDLERS

CAP CDS Plugin that enables classes for entities in a structured way + implementing an additional layer for service classes to separate the implementation for requests to external api's.

Installation

npm install cds-plugin-handlers

Usage

Create a folder "handlers" in the "src" folder. Inside the "handlers" folder you have to create a folder for each service, e.g.: "CatalogService" for the service CatalogService. In here, you have to create a handler class for each entity, e.g.: "BooksHandler" for the entity Books.

This plugin also allows you to implement separation by concerns when it comes to external services. All requests to external services or even to different databases can be stored in a folder "services". In here, you have to create a service class for each external service to implement all the needed requests.

The folder structure in the "srv" folder should look like this:

srv
├── src
│   └── handlers
|   |        ├── CatalogService
|   |        |        ├── BooksHandler.ts
│   |        |        └── AnyOtherHandlerY.ts
│   |        └── AnyOtherService
│   |                 └── AnyOtherHandlerX.ts
|   └── services
│           ├── BookService.ts
│           └── AnyOtherServiceX.ts
└── cat-service.cds

Documentation

We have documented this approach already before the plugin but the documentation still applies, only the setup changed. Everthing is explained in the following blog posts:

Demo app

Demo app available on GitHub https://github.com/lemaiwo/cds-plugin-handlers/tree/main/sample

Demo project using services: https://github.com/lemaiwo/ReCAPBTPServiceOverview

About

License:Apache License 2.0


Languages

Language:JavaScript 53.0%Language:TypeScript 47.0%