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

Feature request - ability to use custom faraday middleware #424

Closed
daisy1754 opened this issue Apr 23, 2022 · 6 comments
Closed

Feature request - ability to use custom faraday middleware #424

daisy1754 opened this issue Apr 23, 2022 · 6 comments

Comments

@daisy1754
Copy link

In our application, we use inhouse faraday middleware called RequestMetricsMiddleware to instrument all outgoing request. It would be great if user of library can use custom middleware like below

Plaid::Client.new(config) do |builder|
  builder.use RequestMetricsMiddleware
end
@vorpus
Copy link
Contributor

vorpus commented May 3, 2022

Hi - this will be added in the next release. Will post in this thread once it's released.

configuration = Plaid::Configuration.new
api_client = Plaid::ApiClient.new(configuration)
api_client.create_connection do |builder|
  builder.use Faraday::Response::Logger
end

@ctlevi
Copy link

ctlevi commented May 6, 2022

Just in case you need another example, I believe my team is also blocked on upgrading from v13 to v15 because of this. Here's is our setup:

client = ::Plaid::Client.new(config) do |builder|
  # Log responses, which will include the request_id needed by Plaid support.
  # This needs to come before the Plaid connection setup below because that will set
  # the adapter, which must be the last middleware in Faraday, otherwise it complains.
  builder.use :instrumentation, name: 'request.plaid'
  ::Plaid::Client.build_default_connection(builder)
  # Set a custom timeout that may be configured differently between web & background requests.
  builder.options[:timeout] = Rails.configuration.x.plaid_request_timeout
end

@vorpus
Copy link
Contributor

vorpus commented Jun 13, 2022

Hi sorry for the delayed response
It looks like the change I mentioned above is live, could you let me know if this works for your use case? To use custom middleware, reinitialize the faraday connection object.

@ctlevi
Copy link

ctlevi commented Jun 13, 2022

@vorpus Yes the new documentation in the README to use create_connection worked great for me.

@daisy1754
Copy link
Author

works for me as well, thanks for update

@jpriollaud
Copy link

jpriollaud commented Aug 17, 2022

@vorpus maybe provide some more examples similar to that of @ctlevi to help people through the upgrade path

    intitialized_client = Plaid::ApiClient.new(configuration)

    intitialized_client.create_connection do |builder|
      builder.response :logger, logger
    end

    @client ||= Plaid::PlaidApi.new(intitialized_client)

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

4 participants