Back to Alamofire

ParameterEncoder

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

5.12.02.9 KB
Original Source

ParameterEncoder

public protocol ParameterEncoder : Sendable

A type that can encode any Encodable type into a URLRequest.

`

                encode(_:into:)
                `

Encode the provided Encodable parameters into request.

Throws

An Error when encoding fails. For Alamofire provided encoders, this will be an instance of AFError.parameterEncoderFailed with an associated ParameterEncoderFailureReason.

Declaration

Swift

func encode<Parameters>(_ parameters: Parameters?, into request: URLRequest) throws -> URLRequest where Parameters : Encodable, Parameters : Sendable

Parameters

| parameters |

The Encodable parameter value.

| | request |

The URLRequest into which to encode the parameters.

|

Return Value

A URLRequest with the result of the encoding.

Available where Self == JSONParameterEncoder

`

                json
                ` Extension method 

Provides a default JSONParameterEncoder instance.

Declaration

Swift

public static var json: JSONParameterEncoder { get }

`

                json(encoder:)
                ` Extension method 

Creates a JSONParameterEncoder using the provided JSONEncoder.

Declaration

Swift

public static func json(encoder: JSONEncoder = JSONEncoder()) -> JSONParameterEncoder

Parameters

| encoder |

JSONEncoder used to encode parameters. JSONEncoder() by default.

|

Return Value

The JSONParameterEncoder.

Available where Self == URLEncodedFormParameterEncoder

`

                urlEncodedForm
                ` Extension method 

Provides a default URLEncodedFormParameterEncoder instance.

Declaration

Swift

public static var urlEncodedForm: URLEncodedFormParameterEncoder { get }

`

                urlEncodedForm(encoder:destination:)
                ` Extension method 

Creates a URLEncodedFormParameterEncoder with the provided encoder and destination.

Declaration

Swift

public static func urlEncodedForm(encoder: URLEncodedFormEncoder = URLEncodedFormEncoder(),
                                  destination: URLEncodedFormParameterEncoder.Destination = .methodDependent) -> URLEncodedFormParameterEncoder

Parameters

| encoder |

URLEncodedFormEncoder used to encode the parameters. URLEncodedFormEncoder() by default.

| | destination |

Destination to which to encode the parameters. .methodDependent by default.

|

Return Value

The URLEncodedFormParameterEncoder.