-
Notifications
You must be signed in to change notification settings - Fork 123
Update readme with simple tutorial #2
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
Conversation
nice progress! => one small comment is we generally follow a template for commit messages and PRs, see
=> check out the readme on swift-log and swift-metrics. they roughly have the following sections:
|
README.md
Outdated
|
||
```swift | ||
dependencies: [ | ||
.package(url: "https://github.com/swift-server/swift-nio-http-client.git", from: "1.0.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did we tag yet? if not, maybe be more explicit about that, see swift-log and swift-metrics READMEs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaced with .branch("master")
README.md
Outdated
## Status | ||
|
||
This library provides the following: | ||
1. Async single request methods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"single request methods" is a bit unclear, rephrase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, do you thinks its better now?
README.md
Outdated
This library provides the following: | ||
1. Async single request methods | ||
2. Simple follow-redirect support (cookie headers are dropped) | ||
3. Body download streaming |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Streaming body download
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks
README.md
Outdated
|
||
This library provides the following: | ||
1. Async single request methods | ||
2. Simple follow-redirect support (cookie headers are dropped) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks
README.md
Outdated
4. TLS support | ||
5. Cookie parsing (but not storage) | ||
|
||
## How to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usage guide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
README.md
Outdated
### Request-Response API | ||
The code snippet below illustrates how to make a simple GET request to a remote server: | ||
|
||
```import HTTPClient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"```swift"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed here and in all other blocks
README.md
Outdated
```import HTTPClient | ||
|
||
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew) | ||
let response = try httpClient.get(url: "https://swift.org").wait() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personally i dont love guiding users to use wait
, and where we do we should make a note that this is not the proper way to do things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point! re-wrote example
README.md
Outdated
``` | ||
In this case shutdown of the client is not neccecary. | ||
|
||
Library provides methods for most HTTP-methods. In case you need to have more control over the method, or you want to add headers or body, use ```HTTPRequest``` struct: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Library provides methods for most HTTP-methods -> Most common HTTP methods are supported out of the box
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, thanks!
README.md
Outdated
} | ||
``` | ||
|
||
### Redirect following |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redirects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
README.md
Outdated
``` | ||
|
||
### Redirect following | ||
To enable follow-redirects behaviour, enable in using client configuration: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enable follow-redirects behavior using the client configuration:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
README.md
Outdated
``` | ||
|
||
### Timeouts | ||
Timeouts (connect and read) can be set in the client configuration: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Timeouts (connect and read) can also be set using the client configuration:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
README.md
Outdated
``` | ||
or on per-request basis: | ||
``` | ||
let response = try httpClient.execute(request: request, timeout: Timeout(connectTimeout: .seconds(1), readTimeout: .seconds(1))).wait() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format to be more readable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-formatted, is it better now?
README.md
Outdated
``` | ||
|
||
### Streaming | ||
In case greater control over body processing is needed or you want to process HTTP Reponse body in a streaming manner, following delegate protocol could be used (example shows how to count bytes in response body without copiying it to the memory): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When dealing with larger amount of data, it's critical to steam the response body instead of aggregating it-memory. Handling a response stream is done using a delegate protocol. The following example demonstrates how to count the number of bytes in a streaming response body:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks
I've re-structured it a bit, what do you think? Should I add more info about architecture? |
README.md
Outdated
@@ -1,3 +1,146 @@ | |||
# swift-nio-http-client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SwiftNIOHTTPClient
README.md
Outdated
``` | ||
and ```SwiftNIOHTTP``` dependency to your target: | ||
```swift | ||
.target(name: "MyApp", dependencies: ["SwiftNIOHTTP"]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
module name should be NIOHTTPClient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've submitted the #4 to fix it
README.md
Outdated
|
||
--- | ||
|
||
**NOTE**: You will need [Xcode 10.2](https://itunes.apple.com/us/app/xcode/id497799835) or [Swift 5.0](https://swift.org/download/#swift-50) to try out `swift-nio-htt-client`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SwiftNIOHTTPClient
README.md
Outdated
or on per-request basis: | ||
```swift | ||
let timeout = Timeout(connectTimeout: .seconds(1), readTimeout: .seconds(1)) | ||
let response = try httpClient.execute(request: request, timeout: timeout).wait() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop wait
``` | ||
or on per-request basis: | ||
```swift | ||
let timeout = Timeout(connectTimeout: .seconds(1), readTimeout: .seconds(1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated to this PR but i would rename connectTimeout
to connect
or connection
and readTimeout
to read
since these are properties of a Timeout
object
README.md
Outdated
``` | ||
|
||
### Streaming | ||
When dealing with larger amount of data, it's critical to steam the response body instead of aggregating it-memory. Handling a response stream is done using a delegate protocol. The following example demonstrates how to count the number of bytes in a streaming response body: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type steam -> stream
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type it-memory -> in-memory
README.md
Outdated
let request = try HTTPRequest(url: "https://swift.org") | ||
let delegate = CountingDelegate() | ||
|
||
let count = try httpClient.execute(request: request, delegate: delegate).wait() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop wait
nice work @artemredkin couple of more small comments. +1 to merge after they are addressed
i think that's a good idea, but we can do a follow up PR to control scope |
* Proposal to fix #362. Allows user to setup a channel with a client certificate and key but still use default root certificates. * fix #362. Respect PR critique. make roots_pem() public. Update Channel init. * fix #362: make roots_pem() return force-unwrapped String. Change Channel API accordingly. * Remove an obsolete comment. * Minor whitespace tweak #1 * Minor whitespace tweak #2
Motivation:
Every library should have a tutorial
Modifications:
Added README.md
Result:
Users will have a tutorial to get started with this library