A client transport that uses the Foundation framework to perform HTTP operations. It is not prescriptive about how this integration works, allowing libraries such as OAuthenticator to be integrated quickly and without any fuss.
Use the transport with client code generated by Swift OpenAPI Generator.
macOS | Linux | iOS | tvOS | watchOS | visionOS |
---|---|---|---|---|---|
✅ 10.15+ | ✅ | ✅ 13+ | ✅ 13+ | ✅ 6+ | ✅ 1+ |
Add the package dependency in your Package.swift
:
.package(url: "https://github.com/tonyarnold/swift-openapi-foundation", from: "0.0.1"),
Next, in your target, add OpenAPIURLSession
to your dependencies:
.target(name: "MyTarget", dependencies: [
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"),
]),
Then, to get started, check out FoundationClientTransport
.
Assuming you've integrated a library such as OAuthenticator into your project, this is all you'll need to do:
let authenticator = Authenticator(config: ...)
let transport = FoundationClientTransport(responseProvider: authenticator.responseProvider)
let client = Client(
serverURL: URL(string: "https://example.com")!,
transport: transport
)
Integrating an existing networking library with OpenAPIFoundation requires you to provide a responseProvider
closure:
let responseProvider: (URLRequest) async throws -> (Data, URLResponse)
This is usually as simple as adding an extension on the networking library's "main" type. You can see how OAuthenticator does this in their repository.