docs/docsets/Alamofire.docset/Contents/Resources/Documents/Structs/URLEncoding.html
public struct URLEncoding : ParameterEncoding
Creates a url-encoded query string to be set as or appended to any existing URL query string or set as the HTTP body of the URL request. Whether the query string is set or appended to any existing URL query string or set as the HTTP body depends on the destination of the encoding.
The Content-Type HTTP header field of an encoded request with HTTP body is 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.
`
Destination
`
Defines whether the url-encoded query string is applied to the existing query string or HTTP body of the resulting URL request.
Swift
public enum Destination : Sendable
`
ArrayEncoding
`
Configures how Array parameters are encoded.
Swift
public enum ArrayEncoding : Sendable
`
BoolEncoding
`
Configures how Bool parameters are encoded.
Swift
public enum BoolEncoding : Sendable
`
default
`
Returns a default URLEncoding instance with a .methodDependent destination.
Swift
public static var `default`: URLEncoding { get }
`
queryString
`
Returns a URLEncoding instance with a .queryString destination.
Swift
public static var queryString: URLEncoding { get }
`
httpBody
`
Returns a URLEncoding instance with an .httpBody destination.
Swift
public static var httpBody: URLEncoding { get }
`
destination
`
The destination defining where the encoded query string is to be applied to the URL request.
Swift
public let destination: Destination
`
arrayEncoding
`
The encoding to use for Array parameters.
Swift
public let arrayEncoding: ArrayEncoding
`
boolEncoding
`
The encoding to use for Bool parameters.
Swift
public let boolEncoding: BoolEncoding
`
init(destination:arrayEncoding:boolEncoding:)
`
Creates an instance using the specified parameters.
Swift
public init(destination: Destination = .methodDependent,
arrayEncoding: ArrayEncoding = .brackets,
boolEncoding: BoolEncoding = .numeric)
| destination |
Destination defining where the encoded query string will be applied. .methodDependent by default.
|
| arrayEncoding |
ArrayEncoding to use. .brackets by default.
|
| boolEncoding |
BoolEncoding to use. .numeric by default.
|
`
encode(_:with:)
`
Swift
public func encode(_ urlRequest: any URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest
`
queryComponents(fromKey:value:)
`
Creates a percent-escaped, URL encoded query string components from the given key-value pair recursively.
Swift
public func queryComponents(fromKey key: String, value: Any) -> [(String, String)]
| key |
Key of the query component.
|
| value |
Value of the query component.
|
The percent-escaped, URL encoded query string components.
`
escape(_:)
`
Creates a percent-escaped string following RFC 3986 for a query string key or value.
Swift
public func escape(_ string: String) -> String
| string |
String to be percent-escaped.
|
The percent-escaped String.