ResultFormat

public enum ResultFormat

Defines the format of the URL response body

  • The body of the response will be JSON decoded

    Declaration

    Swift

    case json
  • Decodes and the provided data into an instance of the provided type, for the current format. If the current format is .raw, the raw Raw (Data) will be returned.

    Throws

    Error if unable to deocde the data based on the current format.

    Declaration

    Swift

    public func decode<T: Decodable>(result: Data, `as` type: T.Type,
                                     dateDecodingStrategy: JSONDecoder.DateDecodingStrategy = .deferredToDate) throws -> T

    Parameters

    result

    The HTTPURLResponse data to decode

    type

    The instance to inflate from the decoded data

    dateDecodingStrategy

    The JSONDecoder.DateDecodingStrategy to use when deserializing Date objects. Defaults to .deferredToDate

    Return Value

    An inflated instance of T

  • Returns a new URLRequest with the appropriately applied headers base on this ResultFormat For example, for .raw, no headers are applied, for .json, application/json headers are set for Accept and Content-Type, etc.

    Declaration

    Swift

    public func headers(for request: URLRequest) -> URLRequest

    Parameters

    request

    The request upon which the HTTPHeaders are to be set.

    Return Value

    A new URLRequest with the set headers.