DecodableResponseSerializer
public final class DecodableResponseSerializer<T> : ResponseSerializer where T : Decodable
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.
-
The
JSONDecoderinstance used to decode responses.Declaration
Swift
public let decoder: DataDecoder -
HTTP response codes for which empty responses are allowed.
Declaration
Swift
public let emptyResponseCodes: Set<Int> -
HTTP request methods for which empty responses are allowed.
Declaration
Swift
public let emptyRequestMethods: Set<HTTPMethod> -
Creates an instance using the values provided.
Declaration
Swift
public init(decoder: DataDecoder = JSONDecoder(), emptyResponseCodes: Set<Int> = DecodableResponseSerializer.defaultEmptyResponseCodes, emptyRequestMethods: Set<HTTPMethod> = DecodableResponseSerializer.defaultEmptyRequestMethods)Parameters
decoderThe
JSONDecoder. Defaults to aJSONDecoder().emptyResponseCodesThe HTTP response codes for which empty responses are allowed. Defaults to
[204, 205].emptyRequestMethodsThe HTTP request methods for which empty responses are allowed. Defaults to
[.head]. -
Declaration
Swift
public func serialize(request: URLRequest?, response: HTTPURLResponse?, data: Data?, error: Error?) throws -> T
View on GitHub
Install in Dash
DecodableResponseSerializer Class Reference