URLSessionAPIAdapter

public final class URLSessionAPIAdapter : APIAdapter

Standard and default implementation of APIAdapter protocol using URLSession.

  • Declaration

    Swift

    public weak var delegate: APIAdapterDelegate?
  • Constructor for APIAdapter based on URLSession.

    Declaration

    Swift

    public init(baseUrl: URL, jsonEncoder: JSONEncoder = JSONEncoder(), jsonDecoder: JSONDecoder = JSONDecoder(), errorType: APIError.Type = StandardAPIError.self, urlSession: URLSession = .shared)

    Parameters

    baseUrl

    Base URI for the server for all API calls this API adapter will be executing.

    jsonEncoder

    Optional JSON encoder used for serialization of JSON models.

    jsonDecoder

    Optional JSON decoder used for deserialization of JSON models.

    errorType

    If we want custom method for error handling instead of returning StandardAPIError This type needs to implement APIError protocol and its optional init requirement.

    urlSession

    Optional URL session (otherwise the standard one will be used). Used mainly if we need our own URLSessionConfiguration or 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)