ResponseDecoder
public struct ResponseDecoder<Response>
A type that can decode a response type from the raw body of a HTTP response.
-
The body of the decoder.
Declaration
Swift
public let decode: (HTTPURLResponse, Data) throws -> Response -
Undocumented
Declaration
Swift
public init(_ decode: @escaping (HTTPURLResponse, Data) throws -> Response)
-
A decoder that always returns a
()value.Declaration
Swift
public static let none: ResponseDecoder<Void>
-
Returns the response data unchanged. Never throws an error.
Declaration
Swift
public static let data: ResponseDecoder<Data>
-
Decodes a UTF8 string from the response data.
Declaration
Swift
public static let text: ResponseDecoder<String> -
Decodes a string from the response data.
Throws
CocoaError.fileReadInapplicableStringEncodingif the encoding is incorrect.Declaration
Swift
public static func text(encoding: String.Encoding) -> ResponseDecoder<String>Parameters
encodingThe encoding of the response data.
-
Decodes a JSON encoded object from some response data.
Throws
Any error that can be thrown by a
JSONDecoder.Declaration
Swift
public static func json<T: Decodable>(encoded resourceType: T.Type, decoder: JSONDecoder = JSONDecoder()) -> ResponseDecoder<T>Parameters
resourceTypeA
Decodableresource type that the decoder should decode.decoderThe JSON decoder to decode the data with. Default
JSONDecoder().
-
Decodes a JSON encoded object from the response data.
Throws
Any error that can be thrown by
JSONDecoder.Declaration
Swift
public static func json(decoder: JSONDecoder = JSONDecoder()) -> ResponseDecoder<Response>Parameters
decoderThe json decoder to decode the data with. Default
JSONDecoder().
View on GitHub
ResponseDecoder Structure Reference