Http
Main class for performing HTTP operations across RESTful resources.
-
Undocumented
-
Initialize an HTTP object.
Declaration
Swift
public init(baseURL: String? = nil, sessionConfig: NSURLSessionConfiguration = NSURLSessionConfiguration.defaultSessionConfiguration(), requestSerializer: RequestSerializer = JsonRequestSerializer(), responseSerializer: ResponseSerializer = JsonResponseSerializer())Parameters
baseURLthe remote base URL of the application (optional).
sessionConfigthe SessionConfiguration object (by default it uses a defaultSessionConfiguration).
requestSerializerthe actual request serializer to use when performing requests.
responseSerializerthe actual response serializer to use upon receiving a response.
Return Value
the newly intitialized HTTP object
-
performs an HTTP GET request.
Declaration
Swift
public func GET(url: String, parameters: [String: AnyObject]? = nil, credential: NSURLCredential? = nil, completionHandler: CompletionBlock)Parameters
urlthe url of the resource.
parametersthe request parameters.
credentialthe credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).
completionHandlerA block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: The object created from the response data of request and the
NSErrorobject describing the network or parsing error that occurred. -
performs an HTTP POST request.
Declaration
Swift
public func POST(url: String, parameters: [String: AnyObject]? = nil, credential: NSURLCredential? = nil, completionHandler: CompletionBlock)Parameters
urlthe url of the resource.
parametersthe request parameters.
credentialthe credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).
completionHandlerA block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: The object created from the response data of request and the
NSErrorobject describing the network or parsing error that occurred. -
performs an HTTP PUT request.
Declaration
Swift
public func PUT(url: String, parameters: [String: AnyObject]? = nil, credential: NSURLCredential? = nil, completionHandler: CompletionBlock)Parameters
urlthe url of the resource.
parametersthe request parameters.
credentialthe credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).
completionHandlerA block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: The object created from the response data of request and the
NSErrorobject describing the network or parsing error that occurred. -
performs an HTTP DELETE request.
Declaration
Swift
public func DELETE(url: String, parameters: [String: AnyObject]? = nil, credential: NSURLCredential? = nil, completionHandler: CompletionBlock)Parameters
urlthe url of the resource.
parametersthe request parameters.
credentialthe credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).
completionHandlerA block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: The object created from the response data of request and the
NSErrorobject describing the network or parsing error that occurred. -
performs an HTTP HEAD request.
Declaration
Swift
public func HEAD(url: String, parameters: [String: AnyObject]? = nil, credential: NSURLCredential? = nil, completionHandler: CompletionBlock)Parameters
urlthe url of the resource.
parametersthe request parameters.
credentialthe credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).
completionHandlerA block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: The object created from the response data of request and the
NSErrorobject describing the network or parsing error that occurred. -
Request to download a file.
Declaration
Swift
public func download(url: String, destinationDirectory: String? = nil, parameters: [String: AnyObject]? = nil, credential: NSURLCredential? = nil, method: HttpMethod = .GET, progress: ProgressBlock?, completionHandler: CompletionBlock)Parameters
urlthe URL of the downloadable resource.
destinationDirectorythe destination directory where the file would be stored, if not specified. application’s default ’.Documents’ directory would be used.
parametersthe request parameters.
credentialthe credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).
methodthe method to be used, by default a .GET request.
progressa block that will be invoked to report progress during download.
completionHandlera block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: The object created from the response data of request and the
NSErrorobject describing the network or parsing error that occurred. -
Request to upload a file using an NURL of a local file.
Declaration
Swift
public func upload(url: String, file: NSURL, parameters: [String: AnyObject]? = nil, credential: NSURLCredential? = nil, method: HttpMethod = .POST, progress: ProgressBlock?, completionHandler: CompletionBlock)Parameters
urlthe URL to upload resource into.
filethe URL of the local file to be uploaded.
parametersthe request parameters.
credentialthe credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).
methodthe method to be used, by default a .POST request.
progressa block that will be invoked to report progress during upload.
completionHandlerA block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: The object created from the response data of request and the
NSErrorobject describing the network or parsing error that occurred. -
Request to upload a file using a raw NSData object.
Declaration
Swift
public func upload(url: String, data: NSData, parameters: [String: AnyObject]? = nil, credential: NSURLCredential? = nil, method: HttpMethod = .POST, progress: ProgressBlock?, completionHandler: CompletionBlock)Parameters
urlthe URL to upload resource into.
datathe data to be uploaded.
parametersthe request parameters.
credentialthe credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).
methodthe method to be used, by default a .POST request.
progressa block that will be invoked to report progress during upload.
completionHandlerA block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: The object created from the response data of request and the
NSErrorobject describing the network or parsing error that occurred. -
Request to upload a file using an NSInputStream object.
Declaration
Swift
public func upload(url: String, stream: NSInputStream, parameters: [String: AnyObject]? = nil, credential: NSURLCredential? = nil, method: HttpMethod = .POST, progress: ProgressBlock?, completionHandler: CompletionBlock)Parameters
urlthe URL to upload resource into.
streamthe stream that will be used for uploading.
parametersthe request parameters.
credentialthe credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).
methodthe method to be used, by default a .POST request.
progressa block that will be invoked to report progress during upload.
completionHandlerA block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: The object created from the response data of request and the
NSErrorobject describing the network or parsing error that occurred.
-
Undocumented
-
Undocumented
View on GitHub
Http Class Reference