cancel
Showing results for 
Search instead for 
Did you mean: 

Send CRUD Requests to CAP Service from custom UI5 App

lukasmetzger
Participant
0 Kudos

Hi Guys,

just a quick question because I did not find anything right about this topic.

How do I send a Request from my Controller, inside my UI5 App?

I have a CAP Project with a working custom UI5 Frontend (deployed to Cloud Foundry).

Now I need to "interact" with the Service f.e. send a "post" request.

Maybe one of you has an idea or a good blog post.

Thanks in advance!

Accepted Solutions (0)

Answers (1)

Answers (1)

jhodel18
Active Contributor
0 Kudos

Hi Lukas,

CAP Services exposes OData V4 model by default, but you can use the OData V2 Proxy Adapter to be able to use OData V2 Model for your UI5 App. There's no special technique in consuming cap backend service from UI5 app. You can refer to the official UI5 documentation:

https://sapui5.hana.ondemand.com/#/topic/8b49fc198bf04b2d9800fc37fecbb218

lukasmetzger
Participant
0 Kudos

Thanks for the answer!

I have trouble deploying my Application to Cloud Foundry!

I implemented a CDS Combinde Backend (CAP Node.js) - Integrated (see: https://www.npmjs.com/package/@sap/cds-odata-v2-adapter-proxy)

It works on localhost, but when I deploy I get "503 Service Not available".

Do you have an idea?

jhodel18
Active Contributor
0 Kudos

That's a very generic error. If you can share your project files or config, I may be able to help.

lukasmetzger
Participant
0 Kudos

I added this server.js file to the srv/ Folder of the Project:

const cds = require("@sap/cds");
const proxy = require("@sap/cds-odata-v2-adapter-proxy");
cds.on("bootstrap", app => app.use(proxy()));
module.exports = cds.server;

Then I ran cds build.

After that I added this to my mta.yaml:

 - name: capv2
    type: nodejs
    path: gen/srv
    build-parameters:
      ignore: ["node_modules/"]
    parameters:
      memory: 256M
      disk-quota: 1G
    provides:
      - name: srv_api_v2
        properties:
          url: "${default-url}"
    requires:
      - name: srv_api
        properties:
          srv_api_url: ~{url}

Then I ran mbt build and cf deploy.

lukasmetzger
Participant
0 Kudos

This is the error i get while deploying:

2020-10-12T07:59:16.60+0000 [APP/PROC/WEB/0] ERR [ERROR] Unable to get xsuaa credentials. Please make sure your app is bound to a single xsuaa service instance or that you provide vcap information in the requires.uaa section.
   2020-10-12T07:59:16.60+0000 [APP/PROC/WEB/0] ERR     at Object.JWT (/home/vcap/deps/0/node_modules/@sap/cds-runtime/lib/common/auth/passport.js:33:29)
   2020-10-12T07:59:16.60+0000 [APP/PROC/WEB/0] ERR     at _initializeStrategy (/home/vcap/deps/0/node_modules/@sap/cds-runtime/lib/common/auth/passport.js:209:27)
   2020-10-12T07:59:16.60+0000 [APP/PROC/WEB/0] ERR     at module.exports (/home/vcap/deps/0/node_modules/@sap/cds-runtime/lib/common/auth/passport.js:298:5)
   2020-10-12T07:59:16.60+0000 [APP/PROC/WEB/0] ERR     at Object.passport (/home/vcap/deps/0/node_modules/@sap/cds-runtime/lib/cds-services/index.js:11:46)
   2020-10-12T07:59:16.60+0000 [APP/PROC/WEB/0] ERR     at Function.in (/home/vcap/deps/0/node_modules/@sap/cds/lib/srv/adapters.js:45:9)
   2020-10-12T07:59:16.60+0000 [APP/PROC/WEB/0] ERR     at ready.then (/home/vcap/deps/0/node_modules/@sap/cds/lib/srv/serve.js:88:39)
   2020-10-12T07:59:16.69+0000 [APP/PROC/WEB/0] ERR npm ERR! code ELIFECYCLE
   2020-10-12T07:59:16.69+0000 [APP/PROC/WEB/0] ERR npm ERR! errno 1
   2020-10-12T07:59:16.69+0000 [APP/PROC/WEB/0] ERR npm ERR! calendarEmpApp@1.0.0 start: `npx cds run`
   2020-10-12T07:59:16.69+0000 [APP/PROC/WEB/0] ERR npm ERR! Exit status 1
   2020-10-12T07:59:16.69+0000 [APP/PROC/WEB/0] ERR npm ERR! 
   2020-10-12T07:59:16.69+0000 [APP/PROC/WEB/0] ERR npm ERR! Failed at the calendarEmpApp@1.0.0 start script.
   2020-10-12T07:59:16.69+0000 [APP/PROC/WEB/0] ERR npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
   2020-10-12T07:59:19.09+0000 [APP/PROC/WEB/0] ERR npm ERR! A complete log of this run can be found in:
   2020-10-12T07:59:19.09+0000 [APP/PROC/WEB/0] ERR npm ERR!     /home/vcap/app/.npm/_logs/2020-10-12T07_59_16_695Z-debug.log