Important note
The focus of this question is on API endpoints that differentiate which resources are returned depending who authenticates, e.g. Alice gets resource A and B returned, and Bob gets resource X and Y.
It is NOT about differentiating the representation of resources returned.
All the endpoints return JSON representations of resources.
Preface
Please consider the following three potential API endpoint designs, all returning thing
resources of a user.
Endpoint A
GET /things
If authentication credentials for <user_x>
are provided with the request, it returns thing
resources that specifically relate to <user_x>
.
For example, authenticating user Alice gets resource A and B returned, and authenticating user Bob gets resource X and Y.
So the differentiation of the response for different authenticating users is on which resource instances are returned and NOT on what information of these instances is returned (i.e. the resource representation).
When authentication fails a 401 response is returned.
Endpoint B
GET /user/<user_x>/things
Endpoint C
GET /things/?user_id=<user_x>
Both endpoint B and C provide the thing
resource instances related to <user_x>
, iff the authenticating user has the right to access these thing
resources.
The representation of the thing
resource instances returned, e.g. what information about the resources is returned, can vary depending which user authenticates. For instance, <user_x>
or an admin user might get back richer data per resource instance then a user with limited access rights.
Authenticating users that don't have any access rights to thing
resources of <user_x>
will get a 401 response.
My questions
I would like to have answers to the following questions:
1) Is Endpoint A RESTful?
2) Does Endpoint A have a good URI design?
3) Are Endpoints B and C RESTful?
4) Do Endpoints B and C have a good URI design?
I'm looking forward to your answers. I also provided my own answers below and would be grateful for feedback on that as well.
Thank you!
— Freddy Snijder