From 033c0fb39ed024f0571cb6e97445908595e6b59b Mon Sep 17 00:00:00 2001 From: Joe Smith Date: Thu, 2 May 2019 12:30:34 -0400 Subject: [PATCH 1/2] Small README fixes --- README.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 37cd5651c..4067c0c3c 100644 --- a/README.md +++ b/README.md @@ -49,8 +49,8 @@ httpClient.get(url: "https://swift.org").whenComplete { result in } ``` -It is important to close client instance after use to cleanly shutdown underlying NIO ```EventLoopGroup```: -``` +It is important to close the client instance, either in a ```defer``` statement or class' ```deinit``` after use to cleanly shutdown underlying NIO ```EventLoopGroup```: +```swift try? httpClient.syncShutdown() ``` Alternatively, you can provide shared ```EventLoopGroup```: @@ -61,7 +61,7 @@ In this case shutdown of the client is not neccecary. ## Usage guide -Most common HTTP methods are supported out of the box. In case you need to have more control over the method, or you want to add headers or body, use ```HTTPRequest``` struct: +Most common HTTP methods are supported out of the box. In case you need to have more control over the method, or you want to add headers or body, use the ```HTTPRequest``` struct: ```swift import NIOHTTPClient @@ -70,7 +70,7 @@ defer { try? httpClient.syncShutdown() } -var request = try HTTPRequest(url: "https://swift.org", method: .POST) +var request = try HTTPClient.HTTPRequest(url: "https://swift.org", method: .POST) request.headers.add(name: "User-Agent", value: "Swift HTTPClient") request.body = .string("some-body") @@ -98,13 +98,13 @@ let httpClient = HTTPClient(eventLoopGroupProvider: .createNew, ### Timeouts Timeouts (connect and read) can also be set using the client configuration: ```swift -let timeout = Timeout(connectTimeout: .seconds(1), readTimeout: .seconds(1)) +let timeout = HTTPClient.Timeout(connect: .seconds(1), read: .seconds(1)) let httpClient = HTTPClient(eventLoopGroupProvider: .createNew, configuration: HTTPClient.Configuration(timeout: timeout)) ``` -or on per-request basis: +or on a per-request basis: ```swift -let timeout = Timeout(connectTimeout: .seconds(1), readTimeout: .seconds(1)) +let timeout = HTTPClient.Timeout(connect: .seconds(1), read: .seconds(1)) httpClient.execute(request: request, timeout: timeout) ``` @@ -115,7 +115,7 @@ class CountingDelegate: HTTPResponseDelegate { typealias Response = Int var count = 0 - + func didTransmitRequestBody() { // this is executed when request is sent, called once } @@ -130,10 +130,11 @@ class CountingDelegate: HTTPResponseDelegate { } func didFinishRequest() throws -> Int { - // this is called when request is fully read, called once, this is where you return a result or throw any errors you require to propagate to the client + // this is called when the request is fully read, called once + // this is where you return a result or throw any errors you require to propagate to the client return count } - + func didReceiveError(_ error: Error) { // this is called when we receive any network-related error, called once } From ee4c6b9e0b0d5d61e03ede8924c98244af1bbd8f Mon Sep 17 00:00:00 2001 From: Joe Smith Date: Fri, 3 May 2019 09:04:52 -0400 Subject: [PATCH 2/2] Single backticks and no deinit --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4067c0c3c..a7ec1771a 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Add the following entry in your Package.swift to start using // it's early days here so we haven't tagged a version yet, but will soon .package(url: "https://github.com/swift-server/swift-nio-http-client.git", .branch("master")) ``` -and ```NIOHTTPClient``` dependency to your target: +and `NIOHTTPClient` dependency to your target: ```swift .target(name: "MyApp", dependencies: ["NIOHTTPClient"]), ``` @@ -49,11 +49,11 @@ httpClient.get(url: "https://swift.org").whenComplete { result in } ``` -It is important to close the client instance, either in a ```defer``` statement or class' ```deinit``` after use to cleanly shutdown underlying NIO ```EventLoopGroup```: +It is important to close the client instance, for example in a `defer` statement, after use to cleanly shutdown the underlying NIO `EventLoopGroup`: ```swift try? httpClient.syncShutdown() ``` -Alternatively, you can provide shared ```EventLoopGroup```: +Alternatively, you can provide shared `EventLoopGroup`: ```swift let httpClient = HTTPClient(eventLoopGroupProvider: .shared(userProvidedGroup)) ``` @@ -61,7 +61,7 @@ In this case shutdown of the client is not neccecary. ## Usage guide -Most common HTTP methods are supported out of the box. In case you need to have more control over the method, or you want to add headers or body, use the ```HTTPRequest``` struct: +Most common HTTP methods are supported out of the box. In case you need to have more control over the method, or you want to add headers or body, use the `HTTPRequest` struct: ```swift import NIOHTTPClient