What’s the best RESTful method to return total number of items in an object?

前端 未结 13 1949
花落未央
花落未央 2020-11-29 15:52

I’m developing a REST API service for a large social networking website I’m involved in. So far, it’s working great. I can issue GET, POST, P

13条回答
  •  爱一瞬间的悲伤
    2020-11-29 16:28

    I prefer using HTTP Headers for this kind of contextual information.

    For the total number of elements, I use the X-total-count header.
    For links to next, previous page, etc. I use HTTP Link header:
    http://www.w3.org/wiki/LinkHeader

    Github does it the same way: https://developer.github.com/v3/#pagination

    In my opinion, it's cleaner since it can be used also when you return content that doesn't support hyperlinks (i.e binaries, pictures).

提交回复
热议问题