Request

open class Request<Parameters> : Validatable where Parameters : Encodable

The Request class should be inherited by any class that represents an API request and sent through the send function in Session.

Only classes that aren’t expecting any data back in the response should directly inherit this class. If data is expected, then ModeledRequest should be used instead.

  • A Bool indicating if the request supports the On-behalf-of header.

    Declaration

    Swift

    open var supportsImpersonation: Bool { get }
  • The HTTP verb to use in the call.

    Declaration

    Swift

    open var method: HTTPMethod
  • The headers to be included in the request.

    Declaration

    Swift

    open var headers: [String : String]
  • The decoding strategy.

    Declaration

    Swift

    open var decodingStrategy: DecodingStrategy
  • The encoding strategy.

    Declaration

    Swift

    open var encodingStrategy: EncodingStrategy
  • The path component of the API endpoint. This should start with a /, for example /v3/mail/send.

    Declaration

    Swift

    open var path: String
  • The parameters that should be sent with the API call. These parameters will either be encoded into the body of the request or the query items of the request

    Declaration

    Swift

    open var parameters: Parameters?
  • Initializes the request.

    Declaration

    Swift

    public init(method: HTTPMethod, path: String, parameters: Parameters? = nil, encodingStrategy: EncodingStrategy = EncodingStrategy(), decodingStrategy: DecodingStrategy = DecodingStrategy())

    Parameters

    method

    The HTTP verb to use in the API call.

    parameters

    Optional parameters to include in the API call.

    path

    The path portion of the API endpoint, such as /v3/mail/send. The path must start with a forward slash (/).

    parameters

    Optional parameters to include in the API call.

    encoding

    The encoding strategy for the parameters.

    decoding

    The decoding strategy for the response.

  • Retrieves a the value of a specific header, or nil if it doesn’t exist.

    Declaration

    Swift

    open func headerValue(named name: String) -> String?

    Parameters

    name

    The name of the header to look for.

    Return Value

    The value, or nil if it doesn’t exist.

  • Validates that the content and accept types are valid.

    Declaration

    Swift

    open func validate() throws
  • Before a Session instance makes an API call, it will call this method to double check that the auth method it’s about to use is supported by the endpoint. In general, this will always return true, however some endpoints, such as the mail send endpoint, only support API keys.

    Declaration

    Swift

    open func supports(auth: Authentication) -> Bool

    Parameters

    auth

    The Authentication instance that’s about to be used.

    Return Value

    A Bool indicating if the authentication method is supported.

  • The description of the request, represented as an API Blueprint

    Declaration

    Swift

    public var description: String { get }