File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,47 @@ and responses—such as adding headers or handling authentication—while adapte
6
6
handle the underlying HTTP communication. For more details, see the sections on
7
7
[ middleware] ( ./2.middleware.md ) and [ adapters] ( ./3.adapter.md ) .
8
8
9
+ ## Creating a Client
10
+
11
+ A client is created using ` Tesla.client/2 ` , which takes a list of middleware
12
+ and an adapter.
13
+
14
+ ``` elixir
15
+ client = Tesla .client ([Tesla .Middleware .PathParams , Tesla .Middleware .Logger ])
16
+ ```
17
+
18
+ You can then use the client to make requests:
19
+
20
+ ``` elixir
21
+ Tesla .get (client, " /users/123" )
22
+ ```
23
+
24
+ ### Passing Options to Middleware
25
+
26
+ You can pass options to middleware by registering the middleware as a tuple
27
+ of two elements, where the first element is the middleware module and the
28
+ second is the options.
29
+
30
+ ``` elixir
31
+ client = Tesla .client (
32
+ [{Tesla .Middleware .BaseUrl , " https://api.example.com" }]
33
+ )
34
+ ```
35
+
36
+ ### Passing Adapter
37
+
38
+ By default, the global adapter is used. You can override this by passing an
39
+ adapter to the client.
40
+
41
+ ``` elixir
42
+ client = Tesla .client ([], Tesla .Adapter .Mint )
43
+ ```
44
+ You can also pass options to the adapter.
45
+
46
+ ``` elixir
47
+ client = Tesla .client ([], {Tesla .Adapter .Mint , pool: :my_pool })
48
+ ```
49
+
9
50
## Single-Client (Singleton) Pattern
10
51
11
52
A common approach in applications is to encapsulate client creation within a
You can’t perform that action at this time.
0 commit comments