Published on

Log Faraday Requests and Response Bodies


Today I had to dig into an integration to see what request and responses were being sent and received. This ended up being fairly straightforward. The integration connector uses Faraday as its HTTP client. I ended up adjusting the initialization of the Faraday client to include config for the logger as follows:

class SomeServiceConnector

  def initialize
    @conn = Rails.application.secrets.some_api_url) do |faraday|
      faraday.response :logger,, body: true, bodies: { request: true, response: true }
    @conn.basic_auth(Rails.application.secrets.some_api_username, Rails.application.secrets.some_api_password)

Using just :body true did not work in my case. It simply killed the response used further down after logging. I ended up following this suggestion and instead used body: true, bodies: { request: true, response: true }