Skip to content

Commit 9fbf221

Browse files
authored
Merge pull request #592 from LukasKnuth/patch-1
Explained middleware ordering
2 parents e7c4371 + f3d0c4c commit 9fbf221

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)