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-27Lines changed: 14 additions & 27 deletions
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 down using `httpClient.shutdown()` when you're done with 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
112
103
switch result {
113
104
case .failure(let error):
114
105
// process error
@@ -123,7 +114,9 @@ httpClient.execute(request: request).whenComplete { result in
123
114
```
124
115
125
116
### Redirects following
126
-
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
+
127
120
```swift
128
121
let httpClient =HTTPClient(eventLoopGroupProvider: .singleton,
0 commit comments