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

foundation client #1529

Merged
merged 1 commit into from Mar 2, 2018

Conversation

2 participants
@tanner0101
Copy link
Member

tanner0101 commented Feb 28, 2018

  • adds a FoundationClient class that implements Client protocol using URLSession. This provides a useful but less performant alternative to EngineClient.

Create a single FoundationClient

let client = try req.make(FoundationClient.self)
...

Or prefer FoundationClient globally

var config = Config.default()
config.prefer(FoundationClient.self, for: Client.self)
let app = try Application(config: config)
let client = try app.make(Client.self)
print(client is FoundationClient) // true

Use just like EngineClient

...
let res = try client.send(.get, to: "http://vapor.codes")
debugPrint(res)

@tanner0101 tanner0101 added this to the 3.0.0-rc.2 milestone Feb 28, 2018

@tanner0101 tanner0101 self-assigned this Feb 28, 2018

/// Converts an `HTTP.HTTPRequest` to `Foundation.URLRequest`
fileprivate func makeFoundationRequest() -> Future<URLRequest> {
let http = self
return http.body.makeData(max: 100_000).map(to: URLRequest.self) { body in

This comment has been minimized.

@Joannis

Joannis Feb 28, 2018

Member

We've been using the max body size of 100KB as a rule of thumb for the max HTTP Body size. For JSONDecoder we can't easily change it (although I think we should consider it). Here, however, we could probably add a parameter so larger bodies are still accepted.

This comment has been minimized.

@tanner0101

tanner0101 Mar 2, 2018

Author Member

This will be changing a bit w/ nio. Let's re-address there

@tanner0101 tanner0101 merged commit 36b1909 into master Mar 2, 2018

2 checks passed

ci/circleci: linux Your tests passed on CircleCI!
Details
dependency-ci Dependencies checked
Details

@tanner0101 tanner0101 deleted the foundation-client branch Mar 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment