1

Is there any recommendation or standard for the payload body of an HTTP response to an HTTP GET request on a collection resource? I cannot find anything in the RFC 7230 family.

The Representational state transfer article on Wikipedia states:

For a collection resource, such as https://api.example.com/collection/, GET retrieves the URIs of the member resources of the collection resource in the response body.

But there is no reference.

With the application/json media type, I have seen sometimes an array of URIs in the response, for instance:

["/collection/item1", "/collection/item2", (…), "/collection/itemN"]

I have also seen objects with "links" keys instead.

Community
  • 1
  • 1
Géry Ogam
  • 6,336
  • 4
  • 38
  • 67

1 Answers1

1

I would answer that : prefer light response to have better performance ! No need to add a (useless) key like "link" or "links" if your endpoint is something like this => "[GET] https://[your domain]/links" - This way, it seems obvious that you will get a link list response. Lot of libraries use same response syntax like this => response.data.items - by this way, you will be able to refactor your code to industrialize the response retrieval.

gcadoret
  • 17
  • 4
  • I would like to use a standard JSON format for this, not a home made JSON format. That way the server can evolve independently without breaking clients, as they would rely on the interface provided by the standard JSON format. – Géry Ogam May 05 '19 at 09:52
  • 1
    So, look at this : https://stackoverflow.com/questions/12806386/standard-json-api-response-format – gcadoret May 06 '19 at 12:51