Good practices for designing REST APIs say that one should use:
GET
requests for the selection of an object (or a collection of objects)POST
requests for the creation of a new object
A pair of examples taken from here:
GET
:https://example.org/api/v1/zoos
selects all the zoosPOST
:https://example.org/api/v1/zoos
creates a new zoo
Now, all these methods are designed to either retrieve an instance (or a set of instances) or modify some instance status.
What about retrieving some statistics on those resources that are stored on the server (e.g., number of zoos stored on the server)? I would not expect something that requires me to download the entire collection and then count the number of documents. Still, I am not sure what should be the right syntax. Is the following:
https://example.org/api/v1/zoos/number
a proper way of doing it? If not, which is the best practice?