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.fileReadInapplicableStringEncoding
if the encoding is incorrect.Declaration
Swift
public static func text(encoding: String.Encoding) -> ResponseDecoder<String>
Parameters
encoding
The 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
resourceType
A
Decodable
resource type that the decoder should decode.decoder
The 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
decoder
The json decoder to decode the data with. Default
JSONDecoder()
.