Skip to content

Commit 79fe8d8

Browse files
author
zhongwencool
committed
add example
1 parent d8c961b commit 79fe8d8

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ Mawell is an HTTP client that provides a common interface over many adapters (su
77

88
It borrow idea from [tesla(elixir)](https://github.com/teamon/tesla) which losely base on [Faraday(ruby)](https://github.com/lostisland/faraday)
99

10+
We already have httpoison and httpotion, why we need another wrapper?
11+
12+
I am trouble with define a lot of `process_url/1` `process_request_headers` `process_response_body` functions,
13+
14+
but those functions almost the same in most cases, we don't need define then every time.
15+
16+
the same operation steps:
17+
18+
1. Put query and url encode together;
19+
2. Add headers
20+
3. Add body
21+
4. Need encode request body with json or multipart
22+
5. Accord reponse's header to decode response body by self
23+
24+
So Maxwell make those same steps into middlewares, it don't lose any flexible.
25+
26+
[See the specific example here](https://gist.github.com/zhongwencool/6cd44df1acd699fc9c7159882ef3b597).
27+
1028
## Usage
1129

1230
Use `Maxwell.Builder` module to create API wrappers.

lib/maxwell.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,6 @@ defmodule Maxwell do
5555
opts: [],
5656
status: nil
5757

58+
use Maxwell.Builder
59+
5860
end

test/maxwell_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ defmodule MiddlewareTest do
125125
use ExUnit.Case
126126

127127
defmodule Client do
128-
use Maxwell.Builder, ~w(get post)
128+
use Maxwell.Builder, ["get", "post"]
129129

130130
middleware Maxwell.Middleware.BaseUrl, "http://example.com"
131131
middleware Maxwell.Middleware.Opts, [connect_timeout: 3000]

0 commit comments

Comments
 (0)