From 7370a10f1a575d2bef3e8dae006f7de199241b70 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Thu, 24 Oct 2024 23:25:57 -0400 Subject: [PATCH] chore: improve adapters docs (#722) --- lib/tesla/adapter/finch.ex | 10 +++++----- lib/tesla/adapter/gun.ex | 9 +++++---- lib/tesla/adapter/hackney.ex | 10 +++++----- lib/tesla/adapter/ibrowse.ex | 10 +++++----- lib/tesla/adapter/mint.ex | 9 +++++---- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/tesla/adapter/finch.ex b/lib/tesla/adapter/finch.ex index 5ed959a6a..62294eca9 100644 --- a/lib/tesla/adapter/finch.ex +++ b/lib/tesla/adapter/finch.ex @@ -6,7 +6,7 @@ if Code.ensure_loaded?(Finch) do Remember to add `{:finch, "~> 0.14.0"}` to dependencies. Also, you need to recompile tesla after adding the `:finch` dependency: - ``` + ```shell mix deps.clean tesla mix compile ``` @@ -24,15 +24,15 @@ if Code.ensure_loaded?(Finch) do You must provide the same name to this adapter: - ``` + ```elixir # set globally in config/config.exs config :tesla, :adapter, {Tesla.Adapter.Finch, name: MyFinch} # set per module defmodule MyClient do - use Tesla - - adapter Tesla.Adapter.Finch, name: MyFinch + def client do + Tesla.client([], {Tesla.Adapter.Finch, name: MyFinch}) + end end ``` diff --git a/lib/tesla/adapter/gun.ex b/lib/tesla/adapter/gun.ex index 4a51cefd9..ca65305ef 100644 --- a/lib/tesla/adapter/gun.ex +++ b/lib/tesla/adapter/gun.ex @@ -8,21 +8,22 @@ if Code.ensure_loaded?(:gun) do In version 1.3 gun sends `host` header with port. Fixed in master branch. Also, you need to recompile tesla after adding `:gun` dependency: - ``` + ```shell mix deps.clean tesla mix deps.compile tesla ``` ## Examples - ``` + ```elixir # set globally in config/config.exs config :tesla, :adapter, Tesla.Adapter.Gun # set per module defmodule MyClient do - use Tesla - adapter Tesla.Adapter.Gun + def client do + Tesla.client([], Tesla.Adapter.Gun) + end end ``` diff --git a/lib/tesla/adapter/hackney.ex b/lib/tesla/adapter/hackney.ex index 3d080787f..f2ded4ba2 100644 --- a/lib/tesla/adapter/hackney.ex +++ b/lib/tesla/adapter/hackney.ex @@ -6,22 +6,22 @@ if Code.ensure_loaded?(:hackney) do Remember to add `{:hackney, "~> 1.13"}` to dependencies (and `:hackney` to applications in `mix.exs`) Also, you need to recompile tesla after adding `:hackney` dependency: - ``` + ```shell mix deps.clean tesla mix deps.compile tesla ``` ## Examples - ``` + ```elixir # set globally in config/config.exs config :tesla, :adapter, Tesla.Adapter.Hackney # set per module defmodule MyClient do - use Tesla - - adapter Tesla.Adapter.Hackney + def client do + Tesla.client([], Tesla.Adapter.Hackney) + end end ``` diff --git a/lib/tesla/adapter/ibrowse.ex b/lib/tesla/adapter/ibrowse.ex index b0174a0d4..a1d40c278 100644 --- a/lib/tesla/adapter/ibrowse.ex +++ b/lib/tesla/adapter/ibrowse.ex @@ -6,22 +6,22 @@ if Code.ensure_loaded?(:ibrowse) do Remember to add `{:ibrowse, "~> 4.2"}` to dependencies (and `:ibrowse` to applications in `mix.exs`) Also, you need to recompile tesla after adding `:ibrowse` dependency: - ``` + ```elixir mix deps.clean tesla mix deps.compile tesla ``` ## Examples - ``` + ```elixir # set globally in config/config.exs config :tesla, :adapter, Tesla.Adapter.Ibrowse # set per module defmodule MyClient do - use Tesla - - adapter Tesla.Adapter.Ibrowse + def client do + Tesla.client([], Tesla.Adapter.Ibrowse) + end end ``` """ diff --git a/lib/tesla/adapter/mint.ex b/lib/tesla/adapter/mint.ex index 03b91530b..8e576e8cf 100644 --- a/lib/tesla/adapter/mint.ex +++ b/lib/tesla/adapter/mint.ex @@ -8,20 +8,21 @@ if Code.ensure_loaded?(Mint.HTTP) do Remember to add `{:mint, "~> 1.0"}` and `{:castore, "~> 0.1"}` to dependencies. Also, you need to recompile tesla after adding `:mint` dependency: - ``` + ```shell mix deps.clean tesla mix deps.compile tesla ``` ## Examples - ``` + ```elixir # set globally in config/config.exs config :tesla, :adapter, Tesla.Adapter.Mint # set per module defmodule MyClient do - use Tesla - adapter Tesla.Adapter.Mint + def client do + Tesla.client([], Tesla.Adapter.Mint) + end end # set global custom cacertfile