cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement a custom handler for a CAP CDS Service with a namespace ?

DSree
Explorer
0 Kudos

Hello,

I am implementing a CAP CDS Service in NodeJS. I would like to use a custom handler for the same.

Example: in the CAP CDS folder srv, I have following file

TestService.cds (Contents)

namespace test.ns.srv;

service TestService {

       function testFunction() returns Integer;

}

 

How should the implementation in TestImplementation.js look? All examples show the service without a namespace and the handler looks like this 

class TestService extends cds.ApplicationService {

    ........

    this.on("testFunction", async (req) => { });

}

 

The above construct works perfectly fine when the TestService.cds definition does not have a namespace. But with namespace, CDS does not link the handler implementation with the service.

 

Thank you

View Entire Topic
Dinu
Contributor

 

The exports' names must match the servce definitions' fully-qualified names.

 Extract from the following part of documentation in https://cap.cloud.sap/docs/node.js/core-services 


In case you have multiple service definition is one .cds file like that:

cds
// services.cds
namespace foo.bar;
service Foo {...}
service Bar {...}

... you may also want to have multiple implementations provided through one corresponding .js file. Simply do so by by having multiple exports like that:

js
// services.js
exports['foo.bar.Foo'] = class Foo {...}
exports['foo.bar.Boo'] = class Bar {...}

The exports' names must match the servce definitions' fully-qualified names.

DSree
Explorer
0 Kudos
thank you. makes sense.