Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify use of X-Total-Count #116

Closed
dehora opened this issue Aug 3, 2016 · 3 comments
Closed

Clarify use of X-Total-Count #116

dehora opened this issue Aug 3, 2016 · 3 comments

Comments

@dehora
Copy link
Member

dehora commented Aug 3, 2016

In "Could: Use Pagination Links Where Applicable", X-Total-Count is mentioned as an option for describing result count.

In JSON (which is the required media type), it's not necessary to ask clients to look in a header when a total count field can be added to the result entity, simplifying client access. The guidelines could be interpreted as saying when you serve pagination links, you are to use X-Total-Count in conjunction with paging links. It would be good to edit the example to include a total count in the data, and making X-Total-Count entirely optional. A final thought I guess is that we should consider avoiding custom headers to work with APIs unless they're strictly needed.


X-Total-Count seems to make most sense in these cases:

  • The design style is to use the the Link header
  • The response media type isn't able to carry the information
  • The JSON response is an array instead of an object

The first two are not directly applicable (Link was removed a while back, we require JSON). The last one is (imho) something we shouldn't encourage because arrays don't afford extensibility the way object based collections/results can (eg you can't easily include pagination links with an array result in the example).

@ePaul
Copy link
Member

ePaul commented Aug 3, 2016

I think you are right here. When we deprecated links in headers, we should have also deprecated this total count in headers.

Of course, when deciding whether to include such a total count at all in your API design, you should consider the performance implications (i.e. your database might need to have a look at all candidate items in order to count them, depending on filter criteria) and whether this information is actually needed.

@dehora
Copy link
Member Author

dehora commented Aug 3, 2016

Of course, when deciding whether to include such a total count at all in your API design,

Absolutely agree; I've seen this a number of times :) Perhaps it could be added as an aside to the guidelines.

@ePaul
Copy link
Member

ePaul commented Aug 16, 2016

During the API Guild meeting we agreed this is a good idea.
@dehora, could you submit a pull request?

dehora added a commit to dehora/restful-api-guidelines that referenced this issue Sep 2, 2016
This makes the X-Total-Count header optional and not preferred
over count data in a JSON result, along with guidance on when
the header can be useful.

For zalando#116
dehora added a commit to dehora/restful-api-guidelines that referenced this issue Sep 2, 2016
This makes the X-Total-Count header optional and not preferred
over count data in a JSON result, along with guidance on when
the header can be useful.

For zalando#116
dehora added a commit to dehora/restful-api-guidelines that referenced this issue Sep 2, 2016
This makes the X-Total-Count header optional and not preferred
over count data in a JSON result, along with guidance on when
the header can be useful.

For zalando#116
dehora added a commit to dehora/restful-api-guidelines that referenced this issue Sep 2, 2016
This makes the X-Total-Count header optional and not preferred
over count data in a JSON result, along with guidance on when
the header can be useful.

For zalando#116
@dehora dehora closed this as completed Sep 16, 2016
daniellehanks pushed a commit to OwletCare/api-style-guide that referenced this issue May 28, 2021
* Updating isort call to check if the repo is using isort v4 or sort v5 +
* Updating isort reqs to 5.8.0
* Isort and black formatting changes

Co-authored-by: Jason Weir <91488+Gidgidonihah@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants