URLRequest

extension URLRequest
  • Convience initializer for easy request creation.

    Important

    path must not start with a /

    Declaration

    Swift

    public init(path: String, baseURL: URL,
                HTTPMethod: HTTPMethod = .GET, parameters: [String: String]? = nil,
                body: Data? = nil, allHTTPHeaderFields: Dictionary<String, String>? = nil)

    Parameters

    path

    path to the resource.

    baseURL

    the base url of the resource.

    HTTPMethod

    the HTTP method for the request. Defaults to .GET

    parameters

    url parameters for the request. Defaults to nil

    body

    body data payload. Defaults to nil

    allHTTPHeaderFields

    HTTP request header fields. Defaults to nil

  • Creates a new URLRequest with HTTPHeaderFields added into the new request. Keep in mind that this overrides header fields which are already contained.

    Declaration

    Swift

    func added(HTTPHeaderFields: [String : String]) -> URLRequest

    Parameters

    HTTPHeaderFields

    the header fileds to add to the request

    Return Value

    a new URLRequest

  • Creates a new URLRequest with query items appended to the new request.

    Declaration

    Swift

    func appending(queryItems: [URLQueryItem], overrideExisting: Bool = true) -> URLRequest

    Parameters

    queryItems

    the query items to append to the request

    overrideExisting

    if `true existing items with the same name will be overridden

    Return Value

    a new URLRequest

  • Creates a new URLRequest with query parameters appended to the new request.

    Declaration

    Swift

    func appending(queryParameters: [String : String], overrideExisting: Bool = true) -> URLRequest

    Parameters

    queryParameters

    the parameters to append to the request

    overrideExisting

    if `true existing items with the same name will be overridden

    Return Value

    a new URLRequest

  • Creates a new URLRequest with all existing query items replaced with new ones.

    Declaration

    Swift

    func replacingAllQueryItems(with queryItems: [URLQueryItem]) -> URLRequest

    Parameters

    queryItems

    the query items to add to the request

    Return Value

    a new URLRequest

  • Creates a new URLRequest with all existing query items replaced with new ones.

    Declaration

    Swift

    func replacingAllQueryItems(with parameters: [String : String]) -> URLRequest

    Parameters

    parameters

    the parameters to add to the request

    Return Value

    a new URLRequest