@@ -24,23 +24,13 @@ An HTTP client for Erlang. Simple, reliable, fast.
2424% % Start hackney
2525application :ensure_all_started (hackney ).
2626
27- % % Simple GET
28- {ok , 200 , _Headers , Body } = hackney :get (<<" https://httpbin.org/get" >>, [], <<>>, [ with_body ] ).
27+ % % Simple GET - the body is returned directly
28+ {ok , 200 , _Headers , Body } = hackney :get (<<" https://httpbin.org/get" >>).
2929
3030% % POST JSON
3131Headers = [{<<" content-type" >>, <<" application/json" >>}],
3232Payload = <<" {\" key\" : \" value\" }" >>,
33- {ok , 201 , _ , _ } = hackney :post (<<" https://httpbin.org/post" >>, Headers , Payload , [with_body ]).
34-
35- % % Stream large response
36- {ok , 200 , _ , Ref } = hackney :get (<<" https://example.com/large-file" >>),
37- stream_body (Ref ).
38-
39- stream_body (Ref ) ->
40- case hackney :stream_body (Ref ) of
41- {ok , Chunk } -> io :format (" ~p bytes~n " , [byte_size (Chunk )]), stream_body (Ref );
42- done -> ok
43- end .
33+ {ok , 200 , _ , _ } = hackney :post (<<" https://httpbin.org/post" >>, Headers , Payload ).
4434```
4535
4636## Installation
@@ -63,7 +53,7 @@ stream_body(Ref) ->
6353| -------| -------------|
6454| [ Getting Started] ( GETTING_STARTED.md ) | Installation, first requests, basic patterns |
6555| [ HTTP Guide] ( guides/http_guide.md ) | Requests, responses, streaming, async, pools |
66- | [ HTTP/2 Guide] ( guides/http2_guide.md ) | HTTP/2 protocol, ALPN, multiplexing, server push |
56+ | [ HTTP/2 Guide] ( guides/http2_guide.md ) | HTTP/2 protocol, ALPN, multiplexing, flow control |
6757| [ HTTP/3 Guide] ( guides/http3_guide.md ) | HTTP/3 over QUIC, opt-in configuration, Alt-Svc |
6858| [ WebSocket Guide] ( guides/websocket_guide.md ) | Connect, send, receive, active mode |
6959| [ Design Guide] ( guides/design.md ) | Architecture, pooling, load regulation internals |
@@ -115,18 +105,9 @@ hackney:finish_send_body(Ref),
115105{ok , Status , _ , Ref } = hackney :start_response (Ref ).
116106```
117107
118- Stream response bodies for downloads:
119-
120- ``` erlang
121- {ok , 200 , _ , Ref } = hackney :get (URL ),
122- read_chunks (Ref ).
123-
124- read_chunks (Ref ) ->
125- case hackney :stream_body (Ref ) of
126- {ok , Data } -> process (Data ), read_chunks (Ref );
127- done -> ok
128- end .
129- ```
108+ Sync responses return the full body directly. To receive a large response
109+ piece-by-piece, use the async API (see the [ Async Responses] ( #async-responses )
110+ section below).
130111
131112### Async Responses
132113
@@ -164,7 +145,7 @@ HTTP/2 is used automatically when the server supports it:
164145
165146``` erlang
166147% % Automatic HTTP/2 via ALPN negotiation
167- {ok , 200 , Headers , Body } = hackney :get (<<" https://nghttp2.org/" >>, [], <<>>, [ with_body ] ).
148+ {ok , 200 , Headers , Body } = hackney :get (<<" https://nghttp2.org/" >>).
168149
169150% % Force HTTP/1.1 only
170151hackney :get (URL , [], <<>>, [{protocols , [http1 ]}]).
@@ -233,7 +214,7 @@ hackney:get(URL, [], <<>>, [
233214
234215``` erlang
235216% % Automatically decompress gzip/deflate responses
236- hackney :get (URL , [], <<>>, [{auto_decompress , true }, with_body ]).
217+ hackney :get (URL , [], <<>>, [{auto_decompress , true }]).
237218```
238219
239220### SSL Options
0 commit comments