Request

public protocol Request

The Request protocol defines the structure for any network requests run through Netable.

  • Parameters will be encoded and sent along with the request.

    Declaration

    Swift

    associatedtype Parameters : Encodable
  • The raw data returned by the server from the request.

    Declaration

    Swift

    associatedtype RawResource
  • An optional convienience type that allows for unwrapping of raw data to a predefined type. See GetCatRequest for a demonstration of this in action.

    Declaration

    Swift

    associatedtype FinalResource = Self.RawResource
  • HTTP method the request will use. Currently GET, POST, PUT and PATCH are supported.

    Declaration

    Swift

    var method: HTTPMethod { get }
  • The path for this request, relative to the base URL defined when you created your Netable instance.

    Declaration

    Swift

    var path: String { get }
  • Parameters to be encoded and sent with the request.

    Declaration

    Swift

    var parameters: Parameters { get }
  • jsonKeyDecodingStrategy Default implementation

    Optional: The key decoding strategy to be used when decoding return JSON.

    Default Implementation

    Set the default key decoding strategy.

    Declaration

    Swift

    var jsonKeyDecodingStrategy: JSONDecoder.KeyDecodingStrategy { get }
  • Optional: The method to decode Data into your RawResource

    Declaration

    Swift

    func decode(_ data: Data?) -> Result<RawResource, NetableError>
  • Optional: The method to convert your RawResource returned by the server to FinalResource.

    Declaration

    Swift

    func finalize(raw: RawResource) -> Result<FinalResource, NetableError>

Available where Parameters == Empty

  • parameters Default implementation

    Default Implementation

    Don’t require filling in parameters for requests that don’t send any.

    Declaration

    Swift

    var parameters: Parameters { get }

Available where FinalResource == RawResource