URLSessionAPIAdapter
public final class URLSessionAPIAdapter : APIAdapter
Standard and default implementation of APIAdapter protocol using URLSession.
-
Declaration
Swift
public weak var delegate: APIAdapterDelegate? -
Constructor for
APIAdapterbased onURLSession.Declaration
Swift
public init(baseUrl: URL, jsonEncoder: JSONEncoder = JSONEncoder(), jsonDecoder: JSONDecoder = JSONDecoder(), errorType: APIError.Type = StandardAPIError.self, urlSession: URLSession = .shared)Parameters
baseUrlBase URI for the server for all API calls this API adapter will be executing.
jsonEncoderOptional JSON encoder used for serialization of JSON models.
jsonDecoderOptional JSON decoder used for deserialization of JSON models.
errorTypeIf we want custom method for error handling instead of returning
StandardAPIErrorThis type needs to implementAPIErrorprotocol and its optional init requirement.urlSessionOptional URL session (otherwise the standard one will be used). Used mainly if we need our own
URLSessionConfigurationor another way of caching (ephemeral session). -
Declaration
Swift
public func request<Endpoint: APIResponseEndpoint>(response endpoint: Endpoint, completion: @escaping (Result<Endpoint.Response, Error>) -> Void) -
Declaration
Swift
public func request(data endpoint: APIEndpoint, completion: @escaping (Result<Data, Error>) -> Void) -
Undocumented
Declaration
Swift
public func dataTask<Endpoint: APIResponseEndpoint>(response endpoint: Endpoint, creation: @escaping (URLSessionTask) -> Void, completion: @escaping (Result<Endpoint.Response, Error>) -> Void) -
Undocumented
Declaration
Swift
public func dataTask(data endpoint: APIEndpoint, creation: @escaping (URLSessionTask) -> Void, completion: @escaping (Result<Data, Error>) -> Void)
View on GitHub
URLSessionAPIAdapter Class Reference