elixir-tesla / tesla

The flexible HTTP client library for Elixir, with support for middleware and multiple adapters.
MIT License
2.01k stars 349 forks source link

feat: override adapter at OTP app level #640

Closed c4710n closed 2 weeks ago

c4710n commented 11 months ago

Thanks for all your hard works, Tesla already has great support on choosing adapter at different levels.

But, it still have one case that tesla doesn't support - override adapter at OTP app level.

This PR adds that feature, which is useful when we want to use different adapter for different OTP apps.


An example - I installed two packages from Hex:

I want to use :finch as the adapter for them all, but due to some reason, I have to set HTTP proxy for bar. But, :finch doesn't support proxy, for now. So I have to use :hackney, which supports proxy.

With this PR, I can do something like:

config :telsa, :adapter, {Tesla.Adapter.Finch, name: MyFinch}
config :tesla, :bar, adapter: Tesla.Adapter.Hackney # override adapter for :bar in an easy way.

Feel free to comment. I can make any modifications necessary to ensure this PR is mergeable. ;)

yordis commented 2 weeks ago

Hey there, sorry it took me this long to get to you; in the latest Tesla version, I removed all documents related to macros to discourage the use of macros without removal. That means that you can pass any adapter using the strategy you wish to Tesla.client/2

I will close the PR; if some folks out there have some serious issue in production that such a feature is granted, please let me know; otherwise, I rather avoid adding even more features that may cause even more work for a v2 breaking change moment.

Thank you so much for your work regardless!