cancel
Showing results for 
Search instead for 
Did you mean: 

CAP NodeJS: Rest Adapter usage with large JSON object leads to 413 - Payload Too Large

martinstenzig
Contributor

What is the best way to increase the message size limitation on the REST adapter?

Temporarily adjusting line 110 in cds/libx/rest/RestAdapter.js

from -> router.use(express.json()) // REVISIT: -> belongs to the parses
to -> router.use(express.json({limit:"50mb"}))

fixes the problem, but what is the appropriate way of working around that limitation?

martinstenzig
Contributor
0 Kudos

Thinking about it a little further. I think there could be 2 long term solutions.

1. A require parameter for the adapter that one can set via cds.env

2. A service level annotation that would allow for the following

@protocol: 'rest'
@messageSize: '50mb'
service MassChangeService {

@open
type AnyArray {};

action insertAll(insEntity : String, insArray: AnyArray) returns AnyArray;

}

Accepted Solutions (1)

Accepted Solutions (1)

OlenaT
Advisor
Advisor

Hi Martin,

Currently the only way to increase payload size in REST is to change the limit parameter of the express object during bootstrapping, something like this:

cds.on("bootstrap", (app) => {
app.use(require("express").json({ limit: '10MB' }))
cds.serve("someService").in(app).to("rest").at("rest");
})

Please note that this will work only for REST. We are working on providing a configuration option, that would allow you to set the maximum request body size. To find out, when this functionality will be available, please keep track of our release notes.

Best regards,

Olena

martinstenzig
Contributor
0 Kudos

Olena, this causes another problem that the other "regular" OData service result in a

Deserialization Error: Unexpected end of JSON input.

I guess the middleware is applied to all adapters and not just to the REST adapter.

OlenaT
Advisor
Advisor
0 Kudos

Hi Martin,

That's what I meant by only works for REST, sorry for not making it clear. We are aware, that providing limit causes problems with OData and we will provide a configuration option for setting maximum body size, that will work for both OData and REST.

Best regards,

Olena

tobias_steckenborn
Active Participant
0 Kudos

Hi @OlenaT,

Is such a configuration available in the meantime? We're hitting the same issue.

Br,
Tobias

OlenaT
Advisor
Advisor
0 Kudos

Hi @tobias_steckenborn,

It's on out to do list, but is not implemented yet.

Best regards,

Olena

Answers (1)

Answers (1)

Daniel7
Advisor
Advisor
0 Kudos

As there will always be a next limit reached, and materializing such large payloads has detrimental effects on resource consumption, I think we need some kind of ootb streaming support for such scenarios, which we don’t have today. → subject for further imp

martinstenzig
Contributor
0 Kudos

daniel.hutzel, Sounds like a plan.

By the way, I was not necessarily suggesting 10MB message sizes, but what I tripped over is that the same message size that does not cause a problem for an OData call, seems to break the Rest adapter.