URLEncodedFormParameterEncoder
open class URLEncodedFormParameterEncoder : ParameterEncoder
A ParameterEncoder
that encodes types as URL-encoded query strings to be set on the URL or as body data, depending
on the Destination
set.
If no Content-Type
header is already set on the provided URLRequest
s, it will be set to
application/x-www-form-urlencoded; charset=utf-8
.
There is no published specification for how to encode collection types. By default, the convention of appending
[]
to the key for array values (foo[]=1&foo[]=2
), and appending the key surrounded by square brackets for
nested dictionary values (foo[bar]=baz
) is used. Optionally, ArrayEncoding
can be used to omit the
square brackets appended to array keys.
BoolEncoding
can be used to configure how boolean values are encoded. The default behavior is to encode
true
as 1 and false
as 0.
-
Defines where the URL-encoded string should be set for each
See moreURLRequest
.Declaration
Swift
public enum Destination
-
Returns an encoder with default parameters.
Declaration
Swift
public static var `default`: URLEncodedFormParameterEncoder { get }
-
The
URLEncodedFormEncoder
to use.Declaration
Swift
public let encoder: URLEncodedFormEncoder
-
The
Destination
for the URL-encoded string.Declaration
Swift
public let destination: Destination
-
Creates an instance with the provided
URLEncodedFormEncoder
instance andDestination
value.Declaration
Swift
public init(encoder: URLEncodedFormEncoder = URLEncodedFormEncoder(), destination: Destination = .methodDependent)
Parameters
encoder
The
URLEncodedFormEncoder
. Defaults toURLEncodedFormEncoder()
.destination
The
Destination
. Defaults to.methodDependent
. -
Declaration
Swift
open func encode<Parameters: Encodable>(_ parameters: Parameters?, into request: URLRequest) throws -> URLRequest