Session
public class Session
Primary class of the library used to perform http request using a Request
object
-
URLRequestTask
Asynchronousa function returning a
RequestData
from aURLRequest
Declaration
Swift
public typealias URLRequestTask = (URLRequest) async throws -> URLDataResponse
-
init the class using a
URLSession
instanceDeclaration
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 returningOutput
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 valueDeclaration
Swift
public func response(for request: Request<Void>) async throws
-
Return a publisher performing request and returning
Output
dataThe 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>