ParameterEncoder
public protocol ParameterEncoder : Sendable
A type that can encode any Encodable
type into a URLRequest
.
-
Encode the provided
Encodable
parameters intorequest
.Throws
An
Error
when encoding fails. For Alamofire provided encoders, this will be an instance ofAFError.parameterEncoderFailed
with an associatedParameterEncoderFailureReason
.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.
-
json
Extension methodProvides a default
JSONParameterEncoder
instance.Declaration
Swift
public static var json: JSONParameterEncoder { get }
-
json(encoder:
Extension method) Creates a
JSONParameterEncoder
using the providedJSONEncoder
.Declaration
Swift
public static func json(encoder: JSONEncoder = JSONEncoder()) -> JSONParameterEncoder
Parameters
encoder
JSONEncoder
used to encode parameters.JSONEncoder()
by default.Return Value
The
JSONParameterEncoder
.
-
urlEncodedForm
Extension methodProvides a default
URLEncodedFormParameterEncoder
instance.Declaration
Swift
public static var urlEncodedForm: URLEncodedFormParameterEncoder { get }
-
urlEncodedForm(encoder:
Extension methoddestination: ) 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