Back to Alamofire

ResponseSerializer

docs/docsets/Alamofire.docset/Contents/Resources/Documents/Protocols/ResponseSerializer.html

5.12.08.5 KB
Original Source

ResponseSerializer

public protocol ResponseSerializer<SerializedObject> : DataResponseSerializerProtocol, DownloadResponseSerializerProtocol

A serializer that can handle both data and download responses.

`

                dataPreprocessor
                ` Default implementation 

DataPreprocessor used to prepare incoming Data for serialization.

Default Implementation

Declaration

Swift

var dataPreprocessor: any DataPreprocessor { get }

`

                emptyRequestMethods
                ` Default implementation 

HTTPMethods for which empty response bodies are considered appropriate.

Default Implementation

Declaration

Swift

var emptyRequestMethods: Set<HTTPMethod> { get }

`

                emptyResponseCodes
                ` Default implementation 

HTTP response codes for which empty response bodies are considered appropriate.

Default Implementation

Declaration

Swift

var emptyResponseCodes: Set<Int> { get }

`

                defaultDataPreprocessor
                ` Extension method 

Default DataPreprocessor. PassthroughPreprocessor by default.

Declaration

Swift

public static var defaultDataPreprocessor: any DataPreprocessor { get }

`

                defaultEmptyRequestMethods
                ` Extension method 

Default HTTPMethods for which empty response bodies are always considered appropriate. [.head] by default.

Declaration

Swift

public static var defaultEmptyRequestMethods: Set<HTTPMethod> { get }

`

                defaultEmptyResponseCodes
                ` Extension method 

HTTP 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, if request exists.

Declaration

Swift

public func requestAllowsEmptyResponseData(_ request: URLRequest?) -> Bool?

Parameters

| request |

URLRequest to evaluate.

|

Return Value

Bool representing the outcome of the evaluation, or nil if request was nil.

`

                responseAllowsEmptyResponseData(_:)
                ` Extension method 

Determines whether the response allows empty response bodies, if response exists.

Declaration

Swift

public func responseAllowsEmptyResponseData(_ response: HTTPURLResponse?) -> Bool?

Parameters

| response |

HTTPURLResponse to evaluate.

|

Return Value

Bool representing the outcome of the evaluation, or nil if response was nil.

`

                emptyResponseAllowed(forRequest:response:)
                ` Extension method 

Determines whether request and response 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 if request or response allow empty bodies, false otherwise.

Decodable

`

                decodable(of:dataPreprocessor:decoder:emptyResponseCodes:emptyRequestMethods:)
                ` Extension method 

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 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.

|

Return Value

The DecodableResponseSerializer.

Available where Self == DataResponseSerializer

`

                data
                ` Extension method 

Provides a default DataResponseSerializer instance.

Declaration

Swift

public static var data: DataResponseSerializer { get }

`

                data(dataPreprocessor:emptyResponseCodes:emptyRequestMethods:)
                ` Extension method 

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 received Data 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

The DataResponseSerializer.

Available where Self == StringResponseSerializer

`

                string
                ` Extension method 

Provides a default StringResponseSerializer instance.

Declaration

Swift

public static var string: StringResponseSerializer { get }

`

                string(dataPreprocessor:encoding:emptyResponseCodes:emptyRequestMethods:)
                ` Extension method 

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 received Data 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

The StringResponseSerializer.