Skip to content

Commit f3d0c4c

Browse files
authored
Explained middleware ordering
1 parent e7c4371 commit f3d0c4c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/tesla/middleware.ex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ defmodule Tesla.Middleware do
1414
or inside tuple in case of dynamic middleware (`Tesla.client/1`):
1515
1616
Tesla.client([{Tesla.Middleware.BaseUrl, "https://example.com"}])
17+
18+
## Ordering
19+
20+
The order in which middleware is defined matters. Note that the order when _sending_ the request
21+
matches the order the middleware was defined in, but the order when _receiving_ the response
22+
is reversed.
23+
24+
For example, `Tesla.Middleware.DecompressResponse` must come _after_ `Tesla.Middleware.JSON`,
25+
otherwise the response isn't decompressed before it reaches the JSON parser.
1726
1827
## Writing custom middleware
1928

0 commit comments

Comments
 (0)