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

    baseURL

    the remote base URL of the application (optional).

    sessionConfig

    the SessionConfiguration object (by default it uses a defaultSessionConfiguration).

    requestSerializer

    the actual request serializer to use when performing requests.

    responseSerializer

    the 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

    url

    the url of the resource.

    parameters

    the request parameters.

    credential

    the credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).

    completionHandler

    A 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 NSError object 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

    url

    the url of the resource.

    parameters

    the request parameters.

    credential

    the credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).

    completionHandler

    A 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 NSError object 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

    url

    the url of the resource.

    parameters

    the request parameters.

    credential

    the credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).

    completionHandler

    A 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 NSError object 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

    url

    the url of the resource.

    parameters

    the request parameters.

    credential

    the credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).

    completionHandler

    A 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 NSError object 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

    url

    the url of the resource.

    parameters

    the request parameters.

    credential

    the credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).

    completionHandler

    A 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 NSError object 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

    url

    the URL of the downloadable resource.

    destinationDirectory

    the destination directory where the file would be stored, if not specified. application’s default ’.Documents’ directory would be used.

    parameters

    the request parameters.

    credential

    the credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).

    method

    the method to be used, by default a .GET request.

    progress

    a block that will be invoked to report progress during download.

    completionHandler

    a 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 NSError object 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

    url

    the URL to upload resource into.

    file

    the URL of the local file to be uploaded.

    parameters

    the request parameters.

    credential

    the credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).

    method

    the method to be used, by default a .POST request.

    progress

    a block that will be invoked to report progress during upload.

    completionHandler

    A 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 NSError object 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

    url

    the URL to upload resource into.

    data

    the data to be uploaded.

    parameters

    the request parameters.

    credential

    the credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).

    method

    the method to be used, by default a .POST request.

    progress

    a block that will be invoked to report progress during upload.

    completionHandler

    A 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 NSError object 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

    url

    the URL to upload resource into.

    stream

    the stream that will be used for uploading.

    parameters

    the request parameters.

    credential

    the credentials to use for basic/digest auth (Note: it is advised that HTTPS should be used by default).

    method

    the method to be used, by default a .POST request.

    progress

    a block that will be invoked to report progress during upload.

    completionHandler

    A 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 NSError object describing the network or parsing error that occurred.