Skip to content

Commit 7a04244

Browse files
committed
explain each example
1 parent b55bf11 commit 7a04244

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Examples/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,19 @@ swift run GetHTML
99
```
1010
To run other examples you can just replace `GetHTML` with the name of the example you want to run.
1111

12+
## [GetHTML](./GetHTML/GetHTML.swift)
13+
14+
This examples sends a HTTP GET request to `https://apple.com/` and first `await`s and `print`s the HTTP Response Head.
15+
Afterwards it buffers the full response body in memory and prints the response as a `String`.
16+
17+
## [GetJSON](./GetJSON/GetJSON.swift)
18+
19+
This examples sends a HTTP GET request to `https://xkcd.com/info.0.json` and first `await`s and `print`s the HTTP Response Head.
20+
Afterwards it buffers the full response body in memory, decodes the buffer using a `JSONDecoder` and `dump`s the decoded response.
21+
22+
## [StreamByteCounter](./StreamByteCounter/StreamByteCounter.swift)
23+
24+
This examples sends a HTTP GET request to `https://apple.com/` and first `await`s and `print`s the HTTP Response Head.
25+
Afterwards it asynchronously iterates over all body fragments, counts the received bytes and prints a progress indicator (if the server send a content-length header).
26+
At the end the total received bytes are printed.
27+
Note that we drop all received fragment and therefore do **not** buffer the whole response body in-memory.

Examples/StreamingByteCounter/StreamingByteCounter.swift

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ struct StreamingByteCounter {
3939
let progress = Double(receivedBytes) / Double(expectedBytes)
4040
print("progress: \(Int(progress * 100))%")
4141
}
42-
// in case backpressure is needed, all reads will be paused until returned future is resolved
4342
}
4443
print("did receive \(receivedBytes) bytes")
4544
} catch {

0 commit comments

Comments
 (0)