Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

DecodableResponseSerializer

mattt edited this page Sep 18, 2020 · 2 revisions

DecodableResponseSerializer

A ResponseSerializer that decodes the response data as a generic value using any type that conforms to DataDecoder. By default, this is an instance of JSONDecoder. Additionally, a request returning nil or no data is considered an error. However, if the response is has a status code valid for empty responses (204, 205), then the Empty.value value is returned.

public final class DecodableResponseSerializer<T:​ Decodable>:​ ResponseSerializer

Inheritance

ResponseSerializer

Initializers

init(dataPreprocessor:​decoder:​emptyResponseCodes:​emptyRequestMethods:​)

Creates an instance using the values provided.

public init(dataPreprocessor:​ DataPreprocessor = DecodableResponseSerializer.defaultDataPreprocessor, decoder:​ DataDecoder = JSONDecoder(), emptyResponseCodes:​ Set<Int> = DecodableResponseSerializer.defaultEmptyResponseCodes, emptyRequestMethods:​ Set<HTTPMethod> = DecodableResponseSerializer.defaultEmptyRequestMethods)

Parameters

  • dataPreprocessor:​ DataPreprocessor used to prepare the received Data for serialization.
  • decoder:​ The DataDecoder. JSONDecoder() by default.
  • emptyResponseCodes:​ The HTTP response codes for which empty responses are allowed. [204, 205] by default.
  • emptyRequestMethods:​ The HTTP request methods for which empty responses are allowed. [.head] by default.

Properties

dataPreprocessor

let dataPreprocessor:​ DataPreprocessor

decoder

The DataDecoder instance used to decode responses.

let decoder:​ DataDecoder

emptyResponseCodes

let emptyResponseCodes:​ Set<Int>

emptyRequestMethods

let emptyRequestMethods:​ Set<HTTPMethod>

Methods

serialize(request:​response:​data:​error:​)

public func serialize(request:​ URLRequest?, response:​ HTTPURLResponse?, data:​ Data?, error:​ Error?) throws -> T
Types
Protocols
Global Typealiases
Clone this wiki locally