Session

public class Session

Primary class of the library used to perform http request using a Request object

  • URLRequestTask Asynchronous

    a function returning a RequestData from a URLRequest

    Declaration

    Swift

    public typealias URLRequestTask = (URLRequest) async throws -> URLDataResponse
  • init the class using a URLSession instance

    Declaration

    Swift

    public convenience init(
        baseURL: URL,
        configuration: SessionConfiguration = SessionConfiguration(),
        urlSession: URLSession = .shared
    )

    Parameters

    baseURL

    common url for all the requests. Allow to switch environments easily

    configuration

    session configuration to use

    urlSession

    URLSession instance to use to make requests.

  • init the class with a base url for request

    Declaration

    Swift

    public init(
        baseURL: URL,
        configuration: SessionConfiguration = SessionConfiguration(),
        dataTask: @escaping URLRequestTask
    )

    Parameters

    baseURL

    common url for all the requests. Allow to switch environments easily

    configuration

    session configuration to use

    dataTask

    publisher used by the class to make http requests. If none provided it default to URLSession.dataPublisher(for:)

  • response(for:) Asynchronous

    Return a publisher performing request and returning Output

    The request is validated and decoded appropriately on success.

    Declaration

    Swift

    public func response<Output>(for request: Request<Output>) async throws -> Output where Output : Decodable

    Return Value

    a async Output on success, an error otherwise

  • response(for:) Asynchronous

    Perform asynchronously request which has no return value

    Declaration

    Swift

    public func response(for request: Request<Void>) async throws
  • Return a publisher performing request and returning Output data

    The request is validated and decoded appropriately on success.

    Declaration

    Swift

    public func publisher<Output>(for request: Request<Output>) -> AnyPublisher<Output, Error> where Output : Decodable

    Return Value

    a Publisher emitting Output on success, an error otherwise

  • Declaration

    Swift

    public func publisher(for request: Request<Void>) -> AnyPublisher<Void, Error>