休息 - 关系和 etag [英] rest - relations and etag

查看:33
本文介绍了休息 - 关系和 etag的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个根资源:

/organizations
/persons

/persons/idGET 调用返回有关某个人的所有信息.

A GET call on /persons/id returns all the information about a certain person.

/persons/id/organizationsGET 调用返回一个人所属的所有组织的数组.

A GET call on /persons/id/organizations returns an array of all the organizations a persons belongs to.

/persons/id/organizations/idGET 调用返回此人所属特定组织的所有信息.它返回与 /organizations/id 中相同的内容.

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.

可以扩展个人信息及其组织信息,将两个 GET 组合成一个 GET:

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

我的问题是关于后一个请求中的 ETag.

My question is about the ETags in the latter request.

访问 /persons/id 时,会在响应头中添加一个 ETag.同样,当访问 /persons/id/organizations/id 时,会在响应头中添加一个 ETag.

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.

现在的问题:访问 /persons/id?expand=organizations 时,我应该将哪个 ETag 添加到响应标头中?

The question now: which ETag should I add to the response headers when accessing /persons/id?expand=organizations?

换句话说,我是否应该在每次更新相关组织时更新一个人的 ETag?

In other words, should I update the ETag of a person each time a related organization is updated?

推荐答案

这取决于您的系统.如果您有全局 ETag,则没有问题.如果每个实体都有一个 ETag(或版本号),并且您想将 ETag 分配给嵌套表示,那么您就会遇到问题...您可以定义自定义标头并将 ETag 与 IRI(URI)一起发送,或者您必须将它们添加到响应正文中.这不是一个完全解决的问题(至少不是 Hydra),我们对此进行了讨论 这里.

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.

这篇关于休息 - 关系和 etag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆