Protocols

The following protocols are available globally.

  • A type that provides an interface to create requests to an API.

    Overview

    For each API, create a type that conforms to RequestProviding and implement the base URL of the API. Using this type you can create Requests for the different endpoints of the API using the construction methods provided by the protocol.

    You can optionally implement the request(to:using:) method to customize the default request provided by the other construction methods.

    See more

    Declaration

    Swift

    public protocol RequestProviding
  • A type that can convert itself into a Foundation URLRequest.

    Overview

    Conforming types provide all the information needed to create a URLRequest for a Resource from an API. The associated Resource type is the type encoded in the body of the response to the request. Conforming types provide a ResponseDecoder<Resource> that is responsible for transforming the raw response data into the associated Resource for the request.

    Conforming to the RequestConvertible Protocol

    Conforming to the RequestConvertible protocol requires you specify an associated Resource type and declare:

    • The base URL for the request.
    • The endpoint for the request.
    • The HTTP method for the request.
    • The decoder for the associated resource type.

    Default implementations of other properties are provided using the values defined in DefaultValue. Where it can be inferred from the Resource type, a default ResponseDecoder is also provided.

    Note

    If your request does not expect a response body, set the associated Resource type to Void.
    See more

    Declaration

    Swift

    public protocol RequestConvertible : CustomStringConvertible