on 02-25-2020 11:16 AM
Hi,
I had a simple requirement. I created 3 api services with their corresponding mta in the same SCP account and deployed them.
https://xxxx.eu10.hana.ondemand.com/srv/testOne
testOne : cds
namespace ntest;
using { cuid } from '@sap/cds/common';
entity testOne : cuid{
quantity: Integer;
}
srv.cds
using {ntest} from '../db/testOne';
service srv {
entity testOne as projection on ntest.testOne;
}
testTwo -> hast the same cds and srv that testOne, but I replaced name testOne for testTwo
https://xxxx.eu10.hana.ondemand.com/srv/testTwo
testThree -> same cds that service testOne and testTwo
https://xxxx.eu10.hana.ondemand.com/srv/testThree
I would like to know how can call in service testThree to services testOne and testTwo.
testthree-service.js
module.exports = cds.service.impl(( srv ) => {
srv.before('CREATE','TestThree', req => {
/** First Call **/
let quantityOne = // I want to get the quantity of the first services
/** Second Call **/
let quantityTwo = // I want to get the quantity of the second services
let Total = quantityOne + quantityTwo
})
});
Should I add the dependencies services in my mta and how to do it?
Can someone please advise on? Any help would be appreciated.
Thank you,
F.
Dear F.,
For inter-service communication you need to create a destination for each service you want to call. For this you can use the destination service on SAP Cloud Foundry: https://help.sap.com/viewer/cca91383641e40ffbe03bdc78f00f681/Cloud/en-US/7e306250e08340f89d6c103e288...
Once this is done, you can use either the SAP Cloud SDK or CAP to trigger synchronous requests to those destinations.
In CAP you have the possibility to import external cds models and create queries using the well-known query APIs. More information can be found here: https://cap.cloud.sap/docs/guides/consuming-services
Best regards,
David
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David,
I could not test untill today and I can not find the way to imported the CDS models.
I want to include the field quantity from the first service into the second services with I call the second service like: testSecond?&$expand=XXXX
Could you please help me with this example?
This is the external service in my package.json
"externalService": {
"kind": "rest/odata",
"model": "api/testOne",
"credentials": {
"destination": "DEST_testOne",
"requestTimeout": 30000
},
External First Service: schema.cds :
namespace my.test;
using { cuid } from '@sap/cds/common';
entity testOne : cuid{
quantity: Integer;
}
External Second Service: schema.cds.
namespace ntest;
using { cuid } from '@sap/cds/common';
entity testSecond : cuid{
quantity: Integer;
testOneId: Association to testOne;
}
Thank you very much.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David,
Thank you very much for you info.
After import external cds models, it is also possible to do Association to one of the import services like that?
namespace my.test;
using { cuid } from '@sap/cds/common';
entity testOne : cuid{
quantity: Integer;
}
namespace ntest;
using { cuid } from '@sap/cds/common';
using { testOne } from 'my.test';// import del modelo
entity testThree : cuid{
quantity: Integer;
testOneId: Association to testOne;
}
It should be works the association?
Best
F.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.