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?
// Get the photos of a user:
GET /user/123/photos
This does not have to actually return the photos, it could return just a list of links.
It could even be a partial list of the first n links with information on the total number, and links to get the next/prev batch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With