You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+14-28
Original file line number
Diff line number
Diff line change
@@ -30,11 +30,9 @@ The code snippet below illustrates how to make a simple GET request to a remote
30
30
```swift
31
31
importAsyncHTTPClient
32
32
33
-
let httpClient =HTTPClient(eventLoopGroupProvider: .singleton)
34
-
35
33
/// MARK: - Using Swift Concurrency
36
34
let request =HTTPClientRequest(url: "https://apple.com/")
37
-
let response =tryawaithttpClient.execute(request, timeout: .seconds(30))
35
+
let response =tryawaitHTTPClient.shared.execute(request, timeout: .seconds(30))
38
36
print("HTTP head", response)
39
37
if response.status == .ok {
40
38
let body =tryawait response.body.collect(upTo: 1024*1024) // 1 MB
@@ -45,7 +43,7 @@ if response.status == .ok {
45
43
46
44
47
45
/// MARK: - Using SwiftNIO EventLoopFuture
48
-
httpClient.get(url: "https://apple.com/").whenComplete { result in
46
+
HTTPClient.shared.get(url: "https://apple.com/").whenComplete { result in
49
47
switch result {
50
48
case .failure(let error):
51
49
// process error
@@ -59,7 +57,8 @@ httpClient.get(url: "https://apple.com/").whenComplete { result in
59
57
}
60
58
```
61
59
62
-
You should always shut down `HTTPClient` instances you created using `try httpClient.shutdown()`. Please note that you must not call `httpClient.shutdown` before all requests of the HTTP client have finished, or else the in-flight requests will likely fail because their network connections are interrupted.
60
+
If you create your own `HTTPClient` instances, you should shut them down using `httpClient.shutdown()` when you're done using them. Failing to do so will leak resources.
61
+
Please note that you must not call `httpClient.shutdown` before all requests of the HTTP client have finished, or else the in-flight requests will likely fail because their network connections are interrupted.
63
62
64
63
### async/await examples
65
64
@@ -74,14 +73,13 @@ The default HTTP Method is `GET`. In case you need to have more control over the
74
73
```swift
75
74
importAsyncHTTPClient
76
75
77
-
let httpClient =HTTPClient(eventLoopGroupProvider: .singleton)
78
76
do {
79
77
var request =HTTPClientRequest(url: "https://apple.com/")
httpClient.execute(request: request).whenComplete { result in
102
+
HTTPClient.shared.execute(request: request).whenComplete { result in
113
103
switch result {
114
104
case .failure(let error):
115
105
// process error
@@ -124,7 +114,9 @@ httpClient.execute(request: request).whenComplete { result in
124
114
```
125
115
126
116
### Redirects following
127
-
Enable follow-redirects behavior using the client configuration:
117
+
118
+
The globally shared instance `HTTPClient.shared` follows redirects by default. If you create your own `HTTPClient`, you can enable the follow-redirects behavior using the client configuration:
119
+
128
120
```swift
129
121
let httpClient =HTTPClient(eventLoopGroupProvider: .singleton,
/// The ``HTTPClient/Configuration`` for ``HTTPClient/shared`` which tries to mimic the platform's default or prevalent browser as closely as possible.
17
+
///
18
+
/// Don't rely on specific values of this configuration as they're subject to change. You can rely on them being somewhat sensible though.
19
+
///
20
+
/// - note: At present, this configuration is nowhere close to a real browser configuration but in case of disagreements we will choose values that match
21
+
/// the default browser as closely as possible.
22
+
///
23
+
/// Platform's default/prevalent browsers that we're trying to match (these might change over time):
0 commit comments