What should be the href of a collection response if I am getting one single item of that collection?

StackOverflow https://stackoverflow.com/questions/16751476

  •  30-05-2022
  •  | 
  •  

Question

Im getting a specific web resource via a http request using GET method.

I've implemented the server to respond using the hypermedia type collection+json so every response is a collection of items according to the specification (http://amundsen.com/media-types/collection/format/#query-templates)

Since the client is requesting a specific item, what should be the content of the href of the collection?

I think it should be the same url of the single item, but I'm not sure.

Was it helpful?

Solution

According to http://www.w3.org/TR/html4/struct/links.html#adef-href, "This attribute specifies the location of a Web resource, thus defining a link between the current element (the source anchor) and the destination anchor defined by this attribute."

If we are requesting the specific element is because we already know its url, then it would be optional to set this attribute. However, it is important to be consistent. If all the other responses of our API include "href", then it would be expected to include this attribute and the value of it could be the same url of the object we want to get.

OTHER TIPS

In case the specific item belongs to a collection, the URI of the collection. In case the item does not belong to a collection (which could be odd and maybe you may check the design of your API) the URL of the item.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top