cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

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

martinstenzig
Contributor
3,117

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?

Accepted Solutions (1)

Accepted Solutions (1)

OlenaT
Product and Topic Expert
Product and Topic Expert

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 Likes

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
Product and Topic Expert
Product and Topic Expert
0 Likes

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
SAP Champion
SAP Champion
0 Likes

Hi @OlenaT,

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

Br,
Tobias

OlenaT
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi @tobias_steckenborn,

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

Best regards,

Olena

Answers (1)

Answers (1)

Daniel7
Product and Topic Expert
Product and Topic Expert
0 Likes

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 Likes

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.

akuller
Participant
0 Likes

Hi @Daniel7, in the meantime, is there a configuration parameter in the service definition or package.json?

tobias_steckenborn
SAP Champion
SAP Champion
@akuller there's not. Yet there's a sample on how to circumvent it during cds bootstrap. It's part of the marked solution.