APIAdapter

public protocol APIAdapter

Protocol describing interface communicating with API resources (most probably over internet). This interface encapsulates executing requests.

Standard implementation of this interface using URLSession is available as URLSessionAPIAdapter.

  • Delegate used for notificating about the currently running request count and asynchronously signing authorized requests.

    Declaration

    Swift

    var delegate: APIAdapterDelegate? { get set }
  • Calls API request endpoint with JSON body and after finishing it calls completion handler with either decoded JSON model or error.

    Declaration

    Swift

    func request<Endpoint: APIResponseEndpoint>(response endpoint: Endpoint, completion: @escaping (Result<Endpoint.Response, Error>) -> Void)

    Parameters

    endpoint

    Response endpoint

    completion

    Completion closure receiving result with automatically decoded JSON model taken from reponse endpoint associated type.

  • Calls API endpoint and after finishing it calls completion handler with either data or error.

    Declaration

    Swift

    func request(data endpoint: APIEndpoint, completion: @escaping (Result<Data, Error>) -> Void)

    Parameters

    endpoint

    Standard endpoint with no response associated type.

    completion

    Completion closure receiving result with data.