Let’s say I have a REST API, which has basic methods to retrieve users and the photos of a user. For example:
// Get a user:
GET /user/123
// Get the photos of a user:
GET /user/123/photos
// Get a photo:
GET /photo/789
This is quite straightforward, however now I also need a method to retrieve the number of photos for a particular user. I don’t want to retrieve all the photos because that would slow everything down and is not necessary. What would be the best way to do that in a REST API?
I thought about implementing something like GET /user/123/photo_count however “photo_count” is not a resource so that doesn’t seem right.
How would I go about presenting this kind of information properly in a REST API?
Like the comment on the original post, you can return the photo count as a property of your user “object”. The
GET /user/123call would simply return an object/json/xml that contains the number of pictures as a property.