ParameterEncoding

public enum ParameterEncoding

Used to specify the way in which a set of parameters are applied to a URL request.

  • URL: Creates a query string to be set as or appended to any existing URL query for GET, HEAD, and DELETE requests, or set as the body for requests with any other HTTP method. The Content-Type HTTP header field of an encoded request with HTTP body is set to application/x-www-form-urlencoded; charset=utf-8. Since there is no published specification for how to encode collection types, 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).

  • URLEncodedInURL: Creates query string to be set as or appended to any existing URL query. Uses the same implementation as the .URL case, but always applies the encoded result to the URL.

  • JSON: Uses NSJSONSerialization to create a JSON representation of the parameters object, which is set as the body of the request. The Content-Type HTTP header field of an encoded request is set to application/json.

  • PropertyList: Uses NSPropertyListSerialization to create a plist representation of the parameters object, according to the associated format and write options values, which is set as the body of the request. The Content-Type HTTP header field of an encoded request is set to application/x-plist.

  • Custom: Uses the associated closure value to construct a new request given an existing request and parameters.

  • URL

    Undocumented

    Declaration

    Swift

    public enum ParameterEncoding
  • Undocumented

    Declaration

    Swift

    public enum ParameterEncoding
  • Undocumented

    Declaration

    Swift

    public enum ParameterEncoding
  • Undocumented

    Declaration

    Swift

    public enum ParameterEncoding
  • Undocumented

    Declaration

    Swift

    public enum ParameterEncoding
  • Creates a URL request by encoding parameters and applying them onto an existing request.

    Declaration

    Swift

    public func encode(
            URLRequest: URLRequestConvertible,
            parameters: [String: AnyObject]?)
            -> (NSMutableURLRequest, NSError?)

    Parameters

    URLRequest

    The request to have parameters applied.

    parameters

    The parameters to apply.

    Return Value

    A tuple containing the constructed request and the error that occurred during parameter encoding, if any.

  • Creates percent-escaped, URL encoded query string components from the given key-value pair using recursion.

    Declaration

    Swift

    public func queryComponents(key: String, _ value: AnyObject) -> [(String, String)]

    Parameters

    key

    The key of the query component.

    value

    The 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) -> String

    Parameters

    string

    The string to be percent-escaped.

    Return Value

    The percent-escaped string.