APIotaClient

public protocol APIotaClient

Defines an API Client.

The definition includes a session, a decoder and a baseURLComponents. that should be used when sending URLRequests to the REST API server specified.

  • A URLSession to use for sending URLRequests from the Client to the REST API.

    Declaration

    Swift

    var session: URLSession { get }
  • A JSONDecoder to use for decoding the responses received by the Client from the REST API.

    Declaration

    Swift

    var decoder: JSONDecoder { get }
  • Used to define the base URL (i.e. host), and any other root-level components of the REST API.

    Declaration

    Swift

    var baseUrlComponents: URLComponents { get }
  • sendRequest(for:callback:) Default implementation

    Send a URLRequest to the specified REST API, returning a response via a callback closure.

    Default Implementation

    Declaration

    Swift

    func sendRequest<T: APIotaCodableEndpoint>(for endpoint: T,
                                               callback: @escaping (Result<T.SuccessResponse, Error>) -> Void)

    Parameters

    endpoint

    An APIotaCodableEndpoint defining the format of the URLRequest to be sent.

    callback

    A closure executed when a response (or an error) is returned as a result of sending the URLRequest to the REST API.

  • sendRequest(for:) Default implementation

    Send a URLRequest to the specified REST API, returning a response via a Combine AnyPublisher.

    Default Implementation

    Declaration

    Swift

    @available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
    func sendRequest<T>(for endpoint: T) -> AnyPublisher<T.SuccessResponse, Error> where T : APIotaCodableEndpoint

    Parameters

    endpoint

    An APIotaCodableEndpoint defining the format of the URLRequest to be sent.

    Return Value

    An AnyPublisher which can be integrated with SwiftUI or Combine code paths.