Session
public class Session
Primary class of the library used to perform http request using a Request object
-
URLRequestTaskAsynchronousa function returning a
RequestDatafrom aURLRequestDeclaration
Swift
public typealias URLRequestTask = (URLRequest) async throws -> URLDataResponse -
init the class using a
URLSessioninstanceDeclaration
Swift
public convenience init( baseURL: URL, configuration: SessionConfiguration = SessionConfiguration(), urlSession: URLSession = .shared )Parameters
baseURLcommon url for all the requests. Allow to switch environments easily
configurationsession configuration to use
urlSessionURLSessioninstance 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
baseURLcommon url for all the requests. Allow to switch environments easily
configurationsession configuration to use
dataTaskpublisher used by the class to make http requests. If none provided it default to
URLSession.dataPublisher(for:) -
response(for:Asynchronous) Return a publisher performing
requestand returningOutputThe request is validated and decoded appropriately on success.
Declaration
Swift
public func response<Output>(for request: Request<Output>) async throws -> Output where Output : DecodableReturn Value
a async Output on success, an error otherwise
-
response(for:Asynchronous) Perform asynchronously
requestwhich has no return valueDeclaration
Swift
public func response(for request: Request<Void>) async throws -
Return a publisher performing request and returning
OutputdataThe request is validated and decoded appropriately on success.
Declaration
Swift
public func publisher<Output>(for request: Request<Output>) -> AnyPublisher<Output, Error> where Output : DecodableReturn Value
a Publisher emitting Output on success, an error otherwise
-
Declaration
Swift
public func publisher(for request: Request<Void>) -> AnyPublisher<Void, Error>
Session Class Reference