ResponseSerializer
public protocol ResponseSerializer<SerializedObject> : DataResponseSerializerProtocol, DownloadResponseSerializerProtocol
A serializer that can handle both data and download responses.
-
dataPreprocessor
Default implementationDataPreprocessor
used to prepare incomingData
for serialization.Default Implementation
Declaration
Swift
var dataPreprocessor: any DataPreprocessor { get }
-
emptyRequestMethods
Default implementationHTTPMethod
s for which empty response bodies are considered appropriate.Default Implementation
Declaration
Swift
var emptyRequestMethods: Set<HTTPMethod> { get }
-
emptyResponseCodes
Default implementationHTTP response codes for which empty response bodies are considered appropriate.
Default Implementation
Declaration
Swift
var emptyResponseCodes: Set<Int> { get }
-
defaultDataPreprocessor
Extension methodDefault
DataPreprocessor
.PassthroughPreprocessor
by default.Declaration
Swift
public static var defaultDataPreprocessor: any DataPreprocessor { get }
-
defaultEmptyRequestMethods
Extension methodDefault
HTTPMethod
s for which empty response bodies are always considered appropriate.[.head]
by default.Declaration
Swift
public static var defaultEmptyRequestMethods: Set<HTTPMethod> { get }
-
defaultEmptyResponseCodes
Extension methodHTTP response codes for which empty response bodies are always considered appropriate.
[204, 205]
by default.Declaration
Swift
public static var defaultEmptyResponseCodes: Set<Int> { get }
-
requestAllowsEmptyResponseData(_:
Extension method) Determines whether the
request
allows empty response bodies, ifrequest
exists.Declaration
Swift
public func requestAllowsEmptyResponseData(_ request: URLRequest?) -> Bool?
Parameters
request
URLRequest
to evaluate.Return Value
Bool
representing the outcome of the evaluation, ornil
ifrequest
wasnil
. -
responseAllowsEmptyResponseData(_:
Extension method) Determines whether the
response
allows empty response bodies, ifresponse
exists.Declaration
Swift
public func responseAllowsEmptyResponseData(_ response: HTTPURLResponse?) -> Bool?
Parameters
response
HTTPURLResponse
to evaluate.Return Value
Bool
representing the outcome of the evaluation, ornil
ifresponse
wasnil
. -
emptyResponseAllowed(forRequest:
Extension methodresponse: ) Determines whether
request
andresponse
allow empty response bodies.Declaration
Swift
public func emptyResponseAllowed(forRequest request: URLRequest?, response: HTTPURLResponse?) -> Bool
Parameters
request
URLRequest
to evaluate.response
HTTPURLResponse
to evaluate.Return Value
true
ifrequest
orresponse
allow empty bodies,false
otherwise.
-
Creates a
DecodableResponseSerializer
using the values provided.Declaration
Swift
public static func decodable<T: Decodable>(of type: T.Type, dataPreprocessor: any DataPreprocessor = DecodableResponseSerializer<T>.defaultDataPreprocessor, decoder: any DataDecoder = JSONDecoder(), emptyResponseCodes: Set<Int> = DecodableResponseSerializer<T>.defaultEmptyResponseCodes, emptyRequestMethods: Set<HTTPMethod> = DecodableResponseSerializer<T>.defaultEmptyRequestMethods) -> DecodableResponseSerializer<T> where Self == DecodableResponseSerializer<T>
Parameters
type
Decodable
type to decode from response data.dataPreprocessor
DataPreprocessor
used to prepare the receivedData
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.Return Value
-
data
Extension methodProvides a default
DataResponseSerializer
instance.Declaration
Swift
public static var data: DataResponseSerializer { get }
-
data(dataPreprocessor:
Extension methodemptyResponseCodes: emptyRequestMethods: ) Creates a
DataResponseSerializer
using the provided parameters.Declaration
Swift
public static func data(dataPreprocessor: any DataPreprocessor = DataResponseSerializer.defaultDataPreprocessor, emptyResponseCodes: Set<Int> = DataResponseSerializer.defaultEmptyResponseCodes, emptyRequestMethods: Set<HTTPMethod> = DataResponseSerializer.defaultEmptyRequestMethods) -> DataResponseSerializer
Parameters
dataPreprocessor
DataPreprocessor
used to prepare the receivedData
for serialization.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.Return Value
-
string
Extension methodProvides a default
StringResponseSerializer
instance.Declaration
Swift
public static var string: StringResponseSerializer { get }
-
Creates a
StringResponseSerializer
with the provided values.Declaration
Swift
public static func string(dataPreprocessor: any DataPreprocessor = StringResponseSerializer.defaultDataPreprocessor, encoding: String.Encoding? = nil, emptyResponseCodes: Set<Int> = StringResponseSerializer.defaultEmptyResponseCodes, emptyRequestMethods: Set<HTTPMethod> = StringResponseSerializer.defaultEmptyRequestMethods) -> StringResponseSerializer
Parameters
dataPreprocessor
DataPreprocessor
used to prepare the receivedData
for serialization.encoding
A string encoding. Defaults to
nil
, in which case the encoding will be determined from the server response, falling back to the default HTTP character set,ISO-8859-1
.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.Return Value