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
pathpath to the resource.
baseURLthe base url of the resource.
HTTPMethodthe HTTP method for the request. Defaults to
.GETparametersurl parameters for the request. Defaults to
nilbodybody data payload. Defaults to
nilallHTTPHeaderFieldsHTTP request header fields. Defaults to
nil
-
Creates a new
URLRequestwith 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]) -> URLRequestParameters
HTTPHeaderFieldsthe header fileds to add to the request
Return Value
a new
URLRequest -
Creates a new
URLRequestwith query items appended to the new request.Declaration
Swift
func appending(queryItems: [URLQueryItem], overrideExisting: Bool = true) -> URLRequestParameters
queryItemsthe query items to append to the request
overrideExistingif `true existing items with the same name will be overridden
Return Value
a new
URLRequest -
Creates a new
URLRequestwith query parameters appended to the new request.Declaration
Swift
func appending(queryParameters: [String : String], overrideExisting: Bool = true) -> URLRequestParameters
queryParametersthe parameters to append to the request
overrideExistingif `true existing items with the same name will be overridden
Return Value
a new
URLRequest -
Creates a new
URLRequestwith all existing query items replaced with new ones.Declaration
Swift
func replacingAllQueryItems(with queryItems: [URLQueryItem]) -> URLRequestParameters
queryItemsthe query items to add to the request
Return Value
a new
URLRequest -
Creates a new
URLRequestwith all existing query items replaced with new ones.Declaration
Swift
func replacingAllQueryItems(with parameters: [String : String]) -> URLRequestParameters
parametersthe parameters to add to the request
Return Value
a new
URLRequest
View on GitHub
URLRequest Extension Reference