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

前端 未结 13 1967
花落未央
花落未央 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:37

    I would recommend adding headers for the same, like:

    HTTP/1.1 200
    
    Pagination-Count: 100
    Pagination-Page: 5
    Pagination-Limit: 20
    Content-Type: application/json
    
    [
      {
        "id": 10,
        "name": "shirt",
        "color": "red",
        "price": "$23"
      },
      {
        "id": 11,
        "name": "shirt",
        "color": "blue",
        "price": "$25"
      }
    ]
    

    For details refer to:

    https://github.com/adnan-kamili/rest-api-response-format

    For swagger file:

    https://github.com/adnan-kamili/swagger-response-template

提交回复
热议问题