HttpClientProtocol
public protocol HttpClientProtocol : Sendable
Protocol defining the contract for HTTP client implementations.
The HttpClientProtocol provides a high-level interface for making HTTP requests
with support for configuration, interceptors, and async/await patterns.
-
Creates a new HTTP request instance.
Declaration
Swift
func request() -> HttpRequestReturn Value
A new
HttpRequestready for configuration. -
request(request:Asynchronous) Executes a pre-configured HTTP request.
Declaration
Swift
func request(request: HttpRequest) async throws -> HttpResponseParameters
requestThe configured HTTP request to execute.
Return Value
An
HttpResponseinstance -
request(builder:Asynchronous) Executes an HTTP request configured via a builder closure.
Example:
let response = try await client.request { req in req.url = URL(string: "https://api.example.com/users") req.setHeader(name: "Accept", value: "application/json") req.get() }Declaration
Swift
func request(builder: @escaping @Sendable (HttpRequest) -> Void) async throws -> HttpResponseParameters
builderA closure that configures the request.
Return Value
An
HttpResponseinstance -
Closes the client and releases resources.
After calling this method, the client should not be used for new requests.
Declaration
Swift
func close()
View on GitHub