URLEncoding
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.
- 
                  
                  
Defines whether the url-encoded query string is applied to the existing query string or HTTP body of the resulting URL request.
- methodDependent: Applies encoded query string result to existing query string for 
GET,HEADandDELETErequests and sets as the HTTP body for requests with any other HTTP method. - queryString: Sets or appends encoded query string result to existing query string.
 - httpBody: Sets encoded query string result as the HTTP body of the URL request.
 
Declaration
Swift
public enum Destination - methodDependent: Applies encoded query string result to existing query string for 
 - 
                  
                  
Configures how
Arrayparameters are encoded.- brackets: An empty set of square brackets is appended to the key for every value. This is the default behavior.
 - noBrackets: No brackets are appended. The key is encoded as is.
 
Declaration
Swift
public enum ArrayEncoding - 
                  
                  
Configures how
Boolparameters are encoded.- numeric:         Encode 
trueas1andfalseas0. This is the default behavior. - literal:         Encode 
trueandfalseas string literals. 
Declaration
Swift
public enum BoolEncoding - numeric:         Encode 
 
- 
                  
                  
Returns a default
URLEncodinginstance.Declaration
Swift
public static var `default`: URLEncoding { get } - 
                  
                  
Returns a
URLEncodinginstance with a.methodDependentdestination.Declaration
Swift
public static var methodDependent: URLEncoding { get } - 
                  
                  
Returns a
URLEncodinginstance with a.queryStringdestination.Declaration
Swift
public static var queryString: URLEncoding { get } - 
                  
                  
Returns a
URLEncodinginstance with an.httpBodydestination.Declaration
Swift
public static var httpBody: URLEncoding { get } - 
                  
                  
The destination defining where the encoded query string is to be applied to the URL request.
Declaration
Swift
public let destination: Destination - 
                  
                  
The encoding to use for
Arrayparameters.Declaration
Swift
public let arrayEncoding: ArrayEncoding - 
                  
                  
The encoding to use for
Boolparameters.Declaration
Swift
public let boolEncoding: BoolEncoding 
- 
                  
                  
Creates a
URLEncodinginstance using the specified destination.Declaration
Swift
public init(destination: Destination = .methodDependent, arrayEncoding: ArrayEncoding = .brackets, boolEncoding: BoolEncoding = .numeric)Parameters
destinationThe destination defining where the encoded query string is to be applied.
arrayEncodingThe encoding to use for
Arrayparameters.boolEncodingThe encoding to use for
Boolparameters.Return Value
The new
URLEncodinginstance. 
- 
                  
                  
Creates a URL request by encoding parameters and applying them onto an existing request.
Throws
An
Errorif the encoding process encounters an error.Declaration
Swift
public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequestParameters
urlRequestThe request to have parameters applied.
parametersThe parameters to apply.
Return Value
The encoded request.
 - 
                  
                  
Creates percent-escaped, URL encoded query string components from the given key-value pair using recursion.
Declaration
Swift
public func queryComponents(fromKey key: String, value: Any) -> [(String, String)]Parameters
keyThe key of the query component.
valueThe value of the query component.
Return Value
The percent-escaped, URL encoded query string components.
 - 
                  
                  
Returns a percent-escaped string following RFC 3986 for a query string key or value.
RFC 3986 states that the following characters are “reserved” characters.
- General Delimiters: “:”, “#”, “[”, “]”, “@”, “?”, “/”
 - Sub-Delimiters: “!”, “$”, “&”, “‘”, “(”, “)”, “*”, “+”, “,”, “;”, “=”
 
In RFC 3986 - Section 3.4, it states that the “?” and “/” characters should not be escaped to allow query strings to include a URL. Therefore, all “reserved” characters with the exception of “?” and “/” should be percent-escaped in the query string.
Declaration
Swift
public func escape(_ string: String) -> StringParameters
stringThe string to be percent-escaped.
Return Value
The percent-escaped string.
 
      URLEncoding Structure Reference