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

Conditional Requests #142

Closed
wants to merge 3 commits into from
Closed

Conditional Requests #142

wants to merge 3 commits into from

Conversation

bratsche
Copy link

@bratsche bratsche commented Oct 4, 2012

Hi, I just took a look at octokit tonight and I really like it. I don't see an obvious way to deal with Github's conditional requests, so I'm making a stab at implementing this myself. Let me know if you have some suggestions for how you'd rather this work.

I added a section to the README for how this works. I tried to implement this so that it has no big changes to the style of the API.

Basically, any API request has an options hash parameter, and I made it so that passing :since or :etag will apply its value to the If-Modified-Since or If-None-Match request headers, respectively.

Then once the request is finished, and since it's a synchronous request, then the client will have two attributes, last_modified and etag, which may be read for the next time this request is made.

@pengwynn
Copy link
Collaborator

Thanks for the patch, but I'd rather see this tackled with some middleware, preferably from Faraday Middleware. And with some tests. 😉

@pengwynn pengwynn closed this Oct 12, 2012
@bratsche
Copy link
Author

Thanks, I'll take a look at Faraday.

@paul
Copy link
Contributor

paul commented Oct 12, 2012

@bratsche I've been working on faraday-cache that should handle this, and quite a bit more. Its sorta half-done, I've been sidetracked on other projects, but I'd love some feedback, or better yet, pull requests.

To use it in octokit, you have to jump through some small hoops:

require 'octokit'
require 'faraday_middleware'

cache = Faraday::Cache::MemoryStore.new

Octokit.configure do |config|
  config.faraday_config do |faraday|
    faraday.request :cache, backend: cache
  end
end

This also requires the latest version of octokit (1.17.1) with the code from #140 in it.

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

Successfully merging this pull request may close these issues.

3 participants