Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support conditional GET requests #7

Open
markpundsack opened this issue Jun 13, 2012 · 1 comment
Open

Support conditional GET requests #7

markpundsack opened this issue Jun 13, 2012 · 1 comment

Comments

@markpundsack
Copy link

I don't see any mention of conditional GET requests. If it's not supported, I'd certainly like it added. If it is supported, perhaps the readme could be updated?

Specifically, what I'm looking for is:

If I make an API request outside of the period, hit the API with appropriate If-Modified-Since and If-None-Match headers, and if the response is a 304 - Not Modified, then serve the cached response.

@mloughran
Copy link
Owner

This feature doesn't exist, but I agree it's a very good idea.

I just had a look at the code to see how this could work. My impression is that rather than building this into the built in HTTP code (which is really just a convenience thing, and which I probably wouldn't add if I was building this again), you want to make it possible to use the previous cached value in the block provided to APICache.get. This way you could store the etag in the cache, and set the appropriate headers when making the HTTP request. One solution would be to pass the Cache object for that key as a block parameter to APICache.get - so in pseudocode you'd be able to write

APICache.get('some_key') do |cache|
  if cache.exists?
    etag = JSON.parse(cache.get)[:etag]
    make_http_request(etag: etag)
  else
    make_http_request
  end
  # ... return etag and body for storage in the cache
end

I'm very happy to accept a pull request for something along these lines :)

On 13 Jun 2012, at 23:45, Mark Pundsack wrote:

I don't see any mention of conditional GET requests. If it's not supported, I'd certainly like it added. If it is supported, perhaps the readme could be updated?

Specifically, what I'm looking for is:

If I make an API request outside of the period, hit the API with appropriate If-Modified-Since and If-None-Match headers, and if the response is a 304 - Not Modified, then serve the cached response.


Reply to this email directly or view it on GitHub:
#7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants