1

When designing RESTful APIs, one of the rules is: "URI designates exactly one resource" , but in the real world we also like good performance and one thing to kill performance is the N+1 problem.

So how exactly are we supposed to avoid the N+1 problem without making more than one URI for the same resource /api/foos/?page=1 or /api/foo/1 where /api/foos/ returns a list of foos in order to get decent performance.

1 Answer 1

3

No one said you can't make a URI for /api/foos/?page=1. A container is not the same as the things it contains; a list of foos is a different resource from the individual foos.

4
  • But conceptually the same entity is at two different URIs now both in /api/foos/?page=1 and /api/foo/1 , but I see what you are saying and it makes sense if we see it like that. Commented Feb 6, 2015 at 20:19
  • 1
    But you can look at it as two different (not independent) resources - you just need to twist your nomenclature slightly so "resource" is not the same thing as "entity." Commented Feb 7, 2015 at 10:42
  • @EsbenSkovPedersen, no: /api/foos/?page=1 is the first page of the container, it should be a list of elements. /api/foos/1 is one element and still the 'real' URL of the resource. Commented Feb 7, 2015 at 15:42
  • There is no issue with a resource being at two URIs. For example you can have myweatherapp.com/today and myweatherapp.com/2015/feb/09 point to the same resource. A URI should only point to one resource, but a resource can have multiple URIs pointing to it. Commented Feb 9, 2015 at 15:47

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.