Skip to content

Small README fixes #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Add the following entry in your <code>Package.swift</code> to start using <code>
// 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"]),
```
Expand All @@ -49,19 +49,19 @@ 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, 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))
```
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

Expand All @@ -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")

Expand Down Expand Up @@ -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)
```

Expand All @@ -115,7 +115,7 @@ class CountingDelegate: HTTPResponseDelegate {
typealias Response = Int

var count = 0

func didTransmitRequestBody() {
// this is executed when request is sent, called once
}
Expand All @@ -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
}
Expand Down