cancel
Showing results for 
Search instead for 
Did you mean: 

​External Remote Odata call without CDS Import in SAP CAP

somnathsap
Explorer
0 Kudos

As we all know that to call remote odata service, We need to use cds import for edmx or we can use axios or different npm module to achieve same. Is there anyway to use cds.connect without edmx import.

Thanks

vneecious
Product and Topic Expert
Product and Topic Expert
View Entire Topic
Bruno-Franzini
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Somnath,

I've tried the following way for a plain (non-OData) Rest API.

package.json file:

´´´"dependencies": { "@sap-cloud-sdk/http-client": "^3.1.1",... } ´´´

"cds": { "requires": { "restApi": { "kind": "rest", "credentials": { "destination": "rest-api-destination" } } } ´´´

in custom handler

const restApi = await connect.to("rest-api-destination");

const { Workspace, Region } = this.entities;

this.on("READ", Workspace, async (req) => {

try {

return await restApi.get(`/Workspace/${req.data.workspaceId}`);

} catch (err) {

if (err.statusCode && err.reason.message) {

req.reject(err.statusCode, err.reason.message);

}

}

});


Note: just used with Non-OData API, I have no idea whether it works or not with OData API.

Kind regards,

Bruno Franzini

somnathsap
Explorer
0 Kudos

Hi Bruno Franzini,

I have noticed We can actually do Get via this. But I having problem in POST call. Can you also check POST call?

Bruno-Franzini
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Somnath, I haven't done a Post call in way yet.