cancel
Showing results for 
Search instead for 
Did you mean: 

Support for actions with unstructured input

helpmesap
Explorer

Hello experts,

does CAP offer support for actions with arbitrary, unstructured and untyped payloads? I need to provide an HTTP endpoint to POST json data to. The json's attributes aren't set in stone and may differ between calls. Is there a way to achieve this using an (unbound) action?

What I'd like to do is to define something along the lines of

// service.cds
service MyService @(path: '/v1') {
    action foo(untyped) returns Integer;
}
// service.js srv.on('foo', async (req) => {
const msg = JSON.stringify(req.data)
console.log(msg)
return 0 })

and then to be able to POST arbitrary payloads like so

### 
POST http://localhost:4004/v1/foo
Content-Type: application/json

{ "baz": "bar" }

###
POST http://localhost:4004/v1/foo
Content-Type: application/json

{ "Number": 125, "An array": [ 1, 2, "Paris", "New York" ] }

Is this possible?

Kind regards
Stan

Accepted Solutions (0)

Answers (0)