实体列表的 HTTP 范围标头
我有这样的资源
/entities # GET, POST
/entities/<id> # GET, PUT, DELETE
GET /entities 获取所有实体的列表。 现在我想轮询更新。单个实体的情况很简单:
GET /entities/2
If-Modified-Since: <http date>
该列表很棘手。我希望响应是自给定时间点以来更新或创建的实体列表。我直观地使用
GET /entities
Range: after <http date>
这是 HTTP 规范的有效请求 http://www.w3 .org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2 。但规范还强制要求 206 Partial Content
响应,其中必须包含 Content-Range
标头。 Content-Range
标头又要求指定字节范围http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16 。这对于我的用例来说显然非常不方便。
您将如何通过 HTTP 请求语义范围?
I have resources like this
/entities # GET, POST
/entities/<id> # GET, PUT, DELETE
GET /entities gets the list of all entities.
Now I want to poll for updates. The case for a single entity is straight forward:
GET /entities/2
If-Modified-Since: <http date>
The list is tricky. I want the response to be a list of entities, updated or created since a given point in time. I'd intuitively use
GET /entities
Range: after <http date>
Which is a valid request by HTTP specification http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2 . But the spec also mandates a 206 Partial Content
response, which has to include a Content-Range
header. A Content-Range
header, in turn, mandates a byte range to be specified http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16 . This is obviously very inconvenient for my use case.
How would you request a semantic range over HTTP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从阅读 14.35.1 部分,我会说Range 标头用于从资源请求特定范围的字节,而不是根据修改时间请求一组实体。
在这种情况下,我认为您应该将范围视为过滤器并将日期作为查询字符串参数传递:
From reading section 14.35.1, I would say that the
Range
header is used to request a specific range of bytes from a resource, not to request a group of entities according to when they were modified.In this case, I believe you should treat your range as a filter and pass the date as a query string parameter: