Skip to content

Adopt the new shared HTTP client #13

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 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio", from: "2.51.0"),
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.17.0"),
.package(url: "https://github.com/apple/swift-nio", from: "2.58.0"),
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.19.0"),
.package(url: "https://github.com/apple/swift-openapi-runtime", .upToNextMinor(from: "0.1.3")),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
],
Expand Down
26 changes: 9 additions & 17 deletions Sources/OpenAPIAsyncHTTPClient/AsyncHTTPClientTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,9 @@ import protocol Foundation.LocalizedError
///
/// ### Use the AsyncHTTPClient transport
///
/// Create the underlying HTTP client:
/// Instantiate the transport:
///
/// let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
///
/// Either store a reference to the client elsewhere and shut it down during
/// cleanup, or add a defer block if the client is only used in the current
/// scope:
///
/// defer {
/// try! httpClient.syncShutdown()
/// }
///
/// Instantiate the transport and provide the HTTP client to it:
///
/// let transport = AsyncHTTPClientTransport(
/// configuration: .init(client: httpClient)
/// )
/// let transport = AsyncHTTPClientTransport()
///
/// Create the base URL of the server to call using your client. If the server
/// URL was defined in the OpenAPI document, you find a generated method for it
Expand All @@ -68,6 +54,12 @@ import protocol Foundation.LocalizedError
///
/// let response = try await client.checkHealth(.init())
/// // ...
///
/// ### Provide a custom Client
///
/// The ``AsyncHTTPClientTransport/Configuration-swift.struct`` type allows you
/// to provide a custom `HTTPClient` and tweak behaviors such as the default
/// timeout.
public struct AsyncHTTPClientTransport: ClientTransport {

/// A set of configuration values for the AsyncHTTPClient transport.
Expand All @@ -83,7 +75,7 @@ public struct AsyncHTTPClientTransport: ClientTransport {
/// - Parameters:
/// - client: The underlying client used to perform HTTP operations.
/// - timeout: The request timeout, defaults to 1 minute.
public init(client: HTTPClient, timeout: TimeAmount = .minutes(1)) {
public init(client: HTTPClient = .init(), timeout: TimeAmount = .minutes(1)) {
self.client = client
self.timeout = timeout
}
Expand Down