Skip to content

Latest commit

 

History

History
39 lines (31 loc) · 1.21 KB

README.md

File metadata and controls

39 lines (31 loc) · 1.21 KB

HTTPRequestClient

A dependency client that handles HTTP requests in apps using the Swift Composable Architecture (TCA).

Usage

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: Decodable

The 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)