What to do about huge resources in REST API

timeslots is a collection resource, why won't you simply enable pagination on that resource

see here: Pagination in a REST web application

calling get on the collection without page information simply returns the first page (with a default page size)

Should I simply let the server comply with this massive request? I think you shouldn't, but that's up to you to decide, can the server handle big volumes? do you find it a valid usecase?


You are free to design your URIs as you want encoding any concept.

So, depending on your users (humans/machines) you can use that as a split on a conceptual level based on your problem space or domain. As you mentioned you probably have something like this:

/users/44/timeslots/afternoon
/users/44/timeslots/offshift
/users/44/timeslots/hours/1
/users/44/timeslots/hours/1
/users/44/timeslots/UTC1624

Once can also limit by the ideas/concepts as above. You filter more by adding queries /users/44/timeslots?day=weekdays&dow=mon

Making use or concept and filters like this will naturally limit the response size. But you need to try design your API not go get into that situation. If your client misbehaves, give it a 400 Bad Request. If something goes wrong on your server side use a 5XX code.

Make use of one of the tools of REST - hypermedia and links (See also HATEOAS) Link to the next part of your hypermedia, make use of "chunk like concepts" that your domain understands (pages, time-slots). No need to download megabytes which also not good for caching which impacts scalability/speed.

Tags:

Rest