Skip to content

Commit 496187c

Browse files
committed
docs: Add example for reading response streams in README
- Added example showing how to read response as binary stream - Added body_format: :binary option usage in HTTP.Response section - Included both quick start and detailed response examples
1 parent 92f3c8c commit 496187c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ IO.puts("Status: #{response.status}")
3434
text = HTTP.Response.text(response)
3535
{:ok, json} = HTTP.Response.json(response)
3636

37+
# Read response as stream (raw binary)
38+
{:ok, response} =
39+
HTTP.fetch("https://jsonplaceholder.typicode.com/posts/1", [
40+
options: [body_format: :binary]
41+
])
42+
|> HTTP.Promise.await()
43+
44+
# response.body is now a binary stream you can process chunk by chunk
45+
binary_data = response.body
46+
3747
# POST request with JSON
3848
{:ok, response} =
3949
HTTP.fetch("https://jsonplaceholder.typicode.com/posts", [
@@ -105,6 +115,16 @@ Represents an HTTP response.
105115
```elixir
106116
text = HTTP.Response.text(response)
107117
{:ok, json} = HTTP.Response.json(response)
118+
119+
# Read response as stream (raw binary)
120+
{:ok, response} =
121+
HTTP.fetch("https://api.example.com/large-file", [
122+
options: [body_format: :binary]
123+
])
124+
|> HTTP.Promise.await()
125+
126+
# Process binary response in chunks
127+
binary_data = response.body
108128
```
109129

110130
### HTTP.Request

0 commit comments

Comments
 (0)