am getting array of objects in request payload and each element of an array is object. So how can I limit this to 10 or 50 or any value? can someone suggest how can I do this?
Why do you want to limit it?
limit array of objects which come in request payload payload is like this": [ {'name': 'abc'}, {'name': 'adef'}..... ]
create a middleware that parses the payload and check that it's an array & array.length is less than limit.
if I dont use middleware I can do something like this: app.post('/', function(req, res){ console.dir(req.body); if(req.body.length > limit){ res.sendStatus(400) } });
better do it in a middleware for re-usability. also make it typesafe.
is status 400 correct status code (i.e bad request) in case of length greater than limit??
413 is the most correct
I want to limit it to certain value because based on that array element I am making SQL query which will return 50-100 records from table so if there are more array elements in payload then the response will be huge thats why want to limit
Why not limit the SQL queries instead?
what will be good idea?? and good practice as well?? limit SQL query records or limit request payload ??
With the LIMIT SQL keyword
Обсуждают сегодня