问题
Say I have two root resources:
/organizations
/persons
A GET
call on /persons/id
returns all the information about a certain person.
A GET
call on /persons/id/organizations
returns an array of all the organizations a persons belongs to.
A GET
call on /persons/id/organizations/id
returns all the information of a specific organization the person belongs to. It returns the same content as in /organizations/id
.
There is a possibility to extend the person information with its organizations information, to combine two GET
into a single GET
:
/persons/id/?expand=organizations
My question is about the ETags in the latter request.
When accessing /persons/id
, an ETag is added to the response headers. Likewise, when accessing /persons/id/organizations/id
, an ETag is added to the response headers.
The question now: which ETag should I add to the response headers when accessing /persons/id?expand=organizations
?
In other words, should I update the ETag of a person each time a related organization is updated?
回答1:
This depends on your system. If you have a global ETag then there is no problem. If you have an ETag (or version number) by every entity, and you want to assign ETags to nested representations, then you have a problem... You can define a custom header and send the ETags along with the IRIs (URIs), or you have to add them to the response body. This is not a fully solved problem (at least not by Hydra), we had a discussion about this here.
来源:https://stackoverflow.com/questions/26427115/rest-relations-and-etag