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

Using Faraday as an adapter #11

Open
romanbsd opened this issue Nov 26, 2013 · 3 comments
Open

Using Faraday as an adapter #11

romanbsd opened this issue Nov 26, 2013 · 3 comments

Comments

@romanbsd
Copy link

We're using the following code for almost a year, so I figured that you might want to put it in wiki or in contrib.

module Zencoder
  class HTTP
    module Faraday
      extend self

      def post(url, options={})
        perform(:post, url, options)
      end

      def put(url, options={})
        perform(:put, url, options)
      end

      def get(url, options={})
        perform(:get, url, options)
      end

      def delete(url, options={})
        perform(:delete, url, options)
      end

      def perform(method, url, options={})
        body = options[:body]
        headers = options[:headers]

        ::Faraday.send(method, url, body, headers)
      end
    end
  end
end

module Faraday
  class Response
    alias_method :code, :status unless defined?(code)
  end
end

Zencoder::HTTP.http_backend = Zencoder::HTTP::Faraday
@corasaurus-hex
Copy link
Contributor

Thanks for the code, but we already have a multi-backend http client bundled in the gem and faraday is another multi-backend http client. I don't really understand why you would want this (especially since the gem uses Net::HTTP by default), so I have to ask: why are you guys using it this way? Also, if we are to accept this into the gem then we would really prefer that it didn't monkey-patch Faraday.

Thanks again!

@romanbsd
Copy link
Author

We are using faraday with net-http-persistent for all of our http requests to external services. We also use instrumentation middleware with Faraday.

@corasaurus-hex
Copy link
Contributor

Sorry for taking so long to get back to you. That makes a lot of sense, especially the instrumentation part. If you'd like to put together a pull request (with tests) we can see about getting this merged in.

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