Creating a Faraday middleware

Posted on 04 Oct 2012 by Eric Oestrich

I’ve been playing around with Faraday recently and wanted to make a middleware. The guide on the wiki leave a little to be desired. Googling didn’t seem to help much either. I eventually found a Faraday Middleware github repo that helped me.

Here is a sample middleware that I ended up using:

class MyMiddleware < Faraday::Middleware
  def call(env)
    env[:request_headers]["My-Custom-Header"] = "my-custom-value"

connection ="") do |faraday|
  faraday.use MyMiddleware
  faraday.adapter Faraday.default_adapter
comments powered by Disqus
Creative Commons License
This site's content is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License unless otherwise specified. Code on this site is licensed under the MIT License unless otherwise specified.