A dependency client that handles HTTP requests in apps using the Swift Composable Architecture (TCA). It is part of the Indigo Stack.
Add the following to your Package.swift file:
dependencies: [
.package(url: "https://github.com/indigo-ce/http-request-client", from: "1.0.0")
]Then, add HTTPRequestClient to your target dependencies:
targets: [
.target(
name: "YourTarget",
dependencies: [
"HTTPRequestClient"
]
)
]The library provides a HTTPRequestClient that has several helpers methods to handle sending requests and decoding the response.
public func send(
_ request: URLRequest,
urlSession: URLSession = .shared
) async throws -> (Data, HTTPURLResponse, UUID)
public func send<Success, Failure>(
_ request: URLRequest,
decoder: JSONDecoder = .init(),
urlSession: URLSession = .shared
) async throws -> Result<Success, Failure> where Success: Decodable, Failure: Decodable
public func send<T>(
_ request: URLRequest,
decoder: JSONDecoder = .init(),
urlSession: URLSession = .shared
) async throws -> T where T: DecodableThe above methods also have variants that support sending a Request type instance from the HTTPRequestBuilder library.
For example:
public func send(
_ request: Request,
baseURL: String,
urlSession: URLSession = .shared,
cachePolicy: URLRequest.CachePolicy = .useProtocolCachePolicy,
timeoutInterval: TimeInterval = 60
) async throws -> (Data, HTTPURLResponse, UUID)This project is licensed under the MIT License. See the LICENSE file for details