Hi - I am having a service which returns collection of users. However at times i need to return only count of collection, rather than the actual resources. How would i achieve the same using json api.
I know count is part of META while returning collection.
In this case
How the service should be designed to return only META
How the client should request such services only for META
If your service supports pagination query params you can send your request with a limit of 0. This would return no actual resources but the meta block should still contain any additional information about the collection such as the total.
You might want to specify an include parameter so that your collection only has id & type attributes. This would lighten the response and allow you to use a generic endpoint. In your case, you’ll ignore the users collection and only concentrate on the meta data to get the count value.
I’ve done as @josh suggested. There’s nothing wrong with requesting a limit of zero. If you do not allow that, you can limit to 1 item; using include would reduce the data being returned.