on 02-23-2021 5:39 PM
Hi,
I have exposed an endpoint using CAP as an action:
auth-service.cds
service AuthService {
action loginAsGuest() returns String;}
auth-service.js
module.exports = (srv) => {
srv.on("loginAsGuest", (req) => {
console.log("I want to use here the payload of my POST request");
});
};
How can I access the payload I send with my POST request to that endpoint? I tried to inspect the request object, but it is so big, that it doesn't fit in the console...
thanks in advance!
Hi "Tocayo",
A service should be inmutable and is called with GET method. You can implement the post as an action.
service TestService {
function calc(a: Integer, b: Integer) returns MyResult;
action acalc(a: Integer, b: Integer) returns MyResult;
}
The implementation.
module.exports = srv => {
srv.on('calc', (req) => ({sum: req.data.a + req.data.b, color:'Green'}))
srv.on('acalc', (req) => ({sum: req.data.a + req.data.b, color:'Green'}))
}
Test
### calc() function
GET http://localhost:4004/nnapi/dns/calc(a=1,b=2)
### calc with post
POST http://localhost:4004/nnapi/dns/acalc
Content-Type: application/json
{ "a": 3, "b":4}
Hope it helps you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.