HTTPClient
async
-friendly wrapper for HTTP clients. It allows a specific client implementation (either Foundation or NIO-based) to be hidden from users of the wrapper.
actor HTTPClient
async
-friendly wrapper for HTTP clients. It allows a specific client implementation (either Foundation or NIO-based) to be hidden from users of the wrapper.
actor HTTPClient
import Basics
protocol Actor : AnyObject, Sendable
Common protocol to which all actors conform.
protocol Sendable
init(configuration: HTTPClientConfiguration = .init(), implementation: Implementation? = nil)
func delete(_ url: URL, headers: HTTPClientHeaders = .init(), options: Request.Options = .init()) async throws -> Response
func execute(_ request: Request, observabilityScope: ObservabilityScope? = nil, progress: ProgressHandler? = nil) async throws -> Response
Execute an HTTP request asynchronously
func get(_ url: URL, headers: HTTPClientHeaders = .init(), options: Request.Options = .init()) async throws -> Response
func head(_ url: URL, headers: HTTPClientHeaders = .init(), options: Request.Options = .init()) async throws -> Response
func post(_ url: URL, body: Data?, headers: HTTPClientHeaders = .init(), options: Request.Options = .init()) async throws -> Response
func put(_ url: URL, body: Data?, headers: HTTPClientHeaders = .init(), options: Request.Options = .init()) async throws -> Response
typealias Configuration = HTTPClientConfiguration
typealias Implementation = (Request, ProgressHandler?) async throws -> Response
typealias ProgressHandler = (_ bytesReceived: Int64, _ totalBytes: Int64?) throws -> Void
typealias Request = HTTPClientRequest
typealias Response = HTTPClientResponse
@backDeployed(before: macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0)
nonisolated func assertIsolated(_ message: @autoclosure () -> String = String(), file: StaticString = #fileID, line: UInt = #line)
Stops program execution if the current task is not executing on this actor’s serial executor.
nonisolated func assumeIsolated<T>(_ operation: (isolated Self) throws -> T, file: StaticString = #fileID, line: UInt = #line) rethrows -> T where T : Sendable
Assume that the current task is executing on this actor’s serial executor, or stop program execution otherwise.
@backDeployed(before: macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0)
nonisolated func preconditionIsolated(_ message: @autoclosure () -> String = String(), file: StaticString = #fileID, line: UInt = #line)
Stops program execution if the current task is not executing on this actor’s serial executor.