HttpService

public protocol HttpService

An HTTP service can be used to abstract a specific endpoint away from specific requests. Usually, you would have one HTTP service per API that you use and possibly different services for testing/staging and production. Intuitively, a specific implementation of an HTTP service represents a particular API.

  • The URL of the API representes by this HTTP service (e.g. api.example.com). This is the only field that needs to be provided by a particular implementation. This url should not contain the scheme (e.g. https://) as it might get overwritten unexpectedly by a request.

    Declaration

    Swift

    var apiUrl: UrlConvertible { get }
  • header Default implementation

    A header that ought to be used by all requests issued against the API represented by this HTTP service. Most commonly, this header contains fields such as the API key or some form of Authorization. Request headers always overwrite header fields set by the HTTP service they are used with. By default, the HTTP service does not set any headers.

    Default Implementation

    Declaration

    Swift

    var header: HttpHeader { get }
  • sessionConfiguration Default implementation

    The session configuration to use for all requests using this service. By default, URLSessionConfiguration.default is used.

    Default Implementation

    Declaration

    Swift

    var sessionConfiguration: URLSessionConfiguration { get }
  • retrierFactory Default implementation

    The retrier factory provides retriers for requests. By default, the default factory of the stateless NilRetrier is used, i.e. requests are never retried.

    Default Implementation

    Declaration

    Swift

    var retrierFactory: RetrierFactory { get }
  • process(_:) Default implementation

    This method may be implemented to perform some action upon failure of a particular request issued against the API represented by this service. As the method does not return anything, it is mainly intended to be used for debugging or global notifications. A common example is, e.g. notifying the user that something has happened via some kind of alert. You may use the notification center to publish failures that are worth reporting to the user. By default, this method does nothing.

    Default Implementation

    Declaration

    Swift

    func process(_ error: Squid.Error)

    Parameters

    error

    The error that caused the failure of a scheduled request.