Something went wrong. Try again.
A HTTP client built with and for PointFree's swift-dependencies
Something went wrong. Try again.
3.3 kB · 97 lines
Swift
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798//// File.swift// //// Created by Woodrow Melling on 12/18/23.//
import Foundationimport Dependenciesimport HTTPTypes
public struct HTTPClientConfiguration: Sendable { public var hostURL: @Sendable () -> String? public var requestHeaders: HTTPFields public var requestInterceptors: [RequestInterceptor] public var responseInterceptors: [ResponseInterceptor] public var errorInterceptors: [ErrorInterceptor] public var jsonDecoder: JSONDecoder public var jsonEncoder: JSONEncoder
public init( hostURL: String?, requestHeaders: HTTPFields, requestInterceptors: [RequestInterceptor], responseInterceptors: [ResponseInterceptor], errorInterceptors: [ErrorInterceptor], jsonDecoder: JSONDecoder, jsonEncoder: JSONEncoder ) { self.hostURL = { hostURL } self.requestHeaders = requestHeaders self.requestInterceptors = requestInterceptors self.responseInterceptors = responseInterceptors self.errorInterceptors = errorInterceptors self.jsonDecoder = jsonDecoder self.jsonEncoder = jsonEncoder }
public init( hostURL: @Sendable @escaping () -> String?, requestHeaders: HTTPFields, requestInterceptors: [RequestInterceptor], responseInterceptors: [ResponseInterceptor], errorInterceptors: [ErrorInterceptor], jsonDecoder: JSONDecoder, jsonEncoder: JSONEncoder ) { self.hostURL = hostURL self.requestHeaders = requestHeaders self.requestInterceptors = requestInterceptors self.responseInterceptors = responseInterceptors self.errorInterceptors = errorInterceptors self.jsonDecoder = jsonDecoder self.jsonEncoder = jsonEncoder }}
extension DependencyValues { public var httpConfiguration: HTTPClientConfiguration { get { return HTTPClientConfiguration( hostURL: self.hostURL, requestHeaders: self.requestHeaders, requestInterceptors: self.requestInterceptors, responseInterceptors: self.responseInterceptors, errorInterceptors: self.errorInterceptors, jsonDecoder: self.jsonDecoder, jsonEncoder: self.jsonEncoder ) } set { self.getHostURL = newValue.hostURL self.requestHeaders = newValue.requestHeaders self.requestInterceptors = newValue.requestInterceptors self.responseInterceptors = newValue.responseInterceptors self.errorInterceptors = newValue.errorInterceptors self.jsonDecoder = newValue.jsonDecoder self.jsonEncoder = newValue.jsonEncoder } }}
enum HostURLDependencyKey: DependencyKey { static let liveValue: @Sendable () -> String? = { nil }}
extension DependencyValues { public var getHostURL: @Sendable () -> String? { get { self[HostURLDependencyKey.self] } set { self[HostURLDependencyKey.self] = newValue } }
public var hostURL: String? { get { self[HostURLDependencyKey.self]() } set { self[HostURLDependencyKey.self] = { @Sendable in newValue }} }}