Skip to content
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

Update readme with simple tutorial #2

Merged
merged 3 commits into from
Apr 10, 2019
Merged

Update readme with simple tutorial #2

merged 3 commits into from
Apr 10, 2019

Conversation

artemredkin
Copy link
Collaborator

@artemredkin artemredkin commented Apr 8, 2019

Motivation:

Every library should have a tutorial

Modifications:

Added README.md

Result:

Users will have a tutorial to get started with this library

@artemredkin artemredkin requested a review from weissi April 8, 2019 14:49
@weissi weissi requested a review from tanner0101 April 8, 2019 18:36
@tomerd
Copy link
Contributor

tomerd commented Apr 9, 2019

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:

  1. overview
  2. tl;dr / getting started guide
  3. detailed design / architecture with examples

README.md Outdated

```swift
dependencies: [
.package(url: "https://github.com/swift-server/swift-nio-http-client.git", from: "1.0.0")
Copy link
Contributor

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

Copy link
Collaborator Author

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
Copy link
Contributor

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?

Copy link
Collaborator Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Streaming body download

Copy link
Collaborator Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

support

Copy link
Collaborator Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usage guide

Copy link
Collaborator Author

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
Copy link
Contributor

@tomerd tomerd Apr 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"```swift"

Copy link
Collaborator Author

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()
Copy link
Contributor

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

Copy link
Collaborator Author

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:
Copy link
Contributor

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

Copy link
Collaborator Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redirects

Copy link
Collaborator Author

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:
Copy link
Contributor

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:

Copy link
Collaborator Author

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:
Copy link
Contributor

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:

Copy link
Collaborator Author

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()
Copy link
Contributor

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

Copy link
Collaborator Author

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):
Copy link
Contributor

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:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, thanks

@artemredkin
Copy link
Collaborator Author

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
Copy link
Contributor

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"]),
Copy link
Contributor

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

Copy link
Collaborator Author

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`.
Copy link
Contributor

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()
Copy link
Contributor

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))
Copy link
Contributor

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type steam -> stream

Copy link
Contributor

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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop wait

@tomerd
Copy link
Contributor

tomerd commented Apr 10, 2019

nice work @artemredkin couple of more small comments. +1 to merge after they are addressed

Should I add more info about architecture?

i think that's a good idea, but we can do a follow up PR to control scope

@artemredkin artemredkin merged commit 43d1b72 into master Apr 10, 2019
@artemredkin artemredkin deleted the updated-readme branch April 10, 2019 22:14
weissi pushed a commit to weissi/async-http-client that referenced this pull request Feb 10, 2020
dnadoba pushed a commit that referenced this pull request Oct 19, 2022
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants