最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

HTTP headers for REST API diff - Stack Overflow

programmeradmin6浏览0评论

I'm building a rest API that has an endpoint for a collection of items. The response is a large JSON array, which takes a while for the client to process. On the server-side, each item in the collection can be independently modified, with an associated modification timestamp.

Instead of fetching the entire collection every time, I'd like to enable the client to be able to specify a timestamp, and get a HTTP 206 Partial Content response, just with the items that have been modified since that timestamp.

I was hoping there might be a standard HTTP header to handle this scenario. I've investigated:

  • Range (which seems to be only for byte ranges)
  • If-Modified-Since (which seems to only control access to the whole resource)

Is there a standard set of HTTP headers to use in requests and responses that deal with diffs, or should I just invent my own?

I'm building a rest API that has an endpoint for a collection of items. The response is a large JSON array, which takes a while for the client to process. On the server-side, each item in the collection can be independently modified, with an associated modification timestamp.

Instead of fetching the entire collection every time, I'd like to enable the client to be able to specify a timestamp, and get a HTTP 206 Partial Content response, just with the items that have been modified since that timestamp.

I was hoping there might be a standard HTTP header to handle this scenario. I've investigated:

  • Range (which seems to be only for byte ranges)
  • If-Modified-Since (which seems to only control access to the whole resource)

Is there a standard set of HTTP headers to use in requests and responses that deal with diffs, or should I just invent my own?

Share Improve this question asked Mar 25 at 17:45 Rob EyreRob Eyre 2,2251 gold badge5 silver badges13 bronze badges 1
  • Don't do this with headers. It should be in the API parameters. – Barmar Commented Mar 25 at 20:12
Add a comment  | 

1 Answer 1

Reset to default 1

There is an extension to HTTP that appears to solve this problem:

https://datatracker.ietf./doc/html/rfc3229

This is quite old. So am I, and I've never seen it used in the wild. Would love to see it in action though!

206 and If-Modified-Since are definitely the wrong tools for the job. Personally I would implement this using a ?since= query parameter.

You could also look at https://www.rfc-editor./rfc/rfc6578.html for inspiration, but this is a WebDAV-specific extension.

发布评论

评论列表(0)

  1. 暂无评论