HttpClient
open class HttpClient : @unchecked Sendable
HttpClient
is responsible for handling HTTP requests and logging the details of those requests and responses.
-
The timeout interval for HTTP requests.
Declaration
Swift
public var timeoutIntervalForRequest: TimeInterval
-
Initializes a new instance of
HttpClient
.Declaration
Swift
public init(session: URLSession = URLSession(configuration: URLSessionConfiguration.default, delegate: RedirectPreventer(), delegateQueue: nil))
Parameters
session
The URLSession instance to be used for HTTP requests. Defaults to a session with
RedirectPreventer
delegate. -
Logs the details of an HTTP request.
Declaration
Swift
public func logRequest(request: URLRequest?)
Parameters
request
The URLRequest to be logged.
-
sendRequest(request:
Asynchronous) Sends an HTTP request and returns the response data and metadata.
Throws
An error if the request fails.Declaration
Swift
public func sendRequest(request: Request) async throws -> (Data, URLResponse)
Parameters
request
The Request object to be sent.
Return Value
A tuple containing the response data and metadata.