Alamofire Docs

Alamofire Reference Request Class Reference

Request

Responsible for sending a request and receiving the response and associated data from the server, as well as managing its underlying NSURLSessionTask.

  • Undocumented

  • Associates an HTTP Basic credential with the request.

    Declaration

    Swift

    public func authenticate(#user: String, password: String) -> Self

    Parameters

    user

    The user.

    password

    The password.

    Return Value

    The request.

  • Sets a closure to be called periodically during the lifecycle of the request as data is written to or read from the server.

    • For uploads, the progress closure returns the bytes written, total bytes written, and total bytes expected to write.
    • For downloads, the progress closure returns the bytes read, total bytes read, and total bytes expected to write.

    Declaration

    Swift

    public func progress(closure: ((Int64, Int64, Int64) -> Void)? = default) -> Self

    Parameters

    closure

    The code to be executed periodically during the lifecycle of the request.

    Return Value

    The request.

  • Adds a handler to be called once the request has finished.

    Declaration

    Swift

    public func response(queue: dispatch_queue_t? = default, serializer: Serializer, completionHandler: (NSURLRequest, NSHTTPURLResponse?, AnyObject?, NSError?) -> Void) -> Self

    Parameters

    queue

    The queue on which the completion handler is dispatched.

    serializer

    The closure responsible for serializing the request, response, and data.

    completionHandler

    The code to be executed once the request has finished.

    Return Value

    The request.

  • The request sent or to be sent to the server.

    Declaration

    Swift

    public var request: NSURLRequest { get }

  • The response received from the server, if any.

    Declaration

    Swift

    public var response: NSHTTPURLResponse? { get }

  • Creates a response serializer that returns the associated data as-is.

    Declaration

    Swift

    public class func responseDataSerializer() -> Serializer

    Return Value

    A data response serializer.

  • A closure used by response handlers that takes a request, response, and data and returns a serialized object and any error that occured in the process.

    Declaration

    Swift

    public typealias Serializer = (NSURLRequest, NSHTTPURLResponse?, NSData?) -> (AnyObject?, NSError?)

  • The underlying task.

    Declaration

    Swift

    public var task: NSURLSessionTask { get }

  • Associates a specified credential with the request.

    Declaration

    Swift

    public func authenticate(usingCredential credential: NSURLCredential) -> Self

    Parameters

    credential

    The credential.

    Return Value

    The request.

  • The progress of the request lifecycle.

    Declaration

    Swift

    public var progress: NSProgress? { get }

  • Adds a handler to be called once the request has finished.

    Declaration

    Swift

    public func response(completionHandler: (NSURLRequest, NSHTTPURLResponse?, AnyObject?, NSError?) -> Void) -> Self

    Parameters

    completionHandler

    The code to be executed once the request has finished.

    Return Value

    The request.

  • The session belonging to the underlying task.

    Declaration

    Swift

    public let session: NSURLSession

  • The underlying task.

    Declaration

    Swift

    public var task: NSURLSessionTask { get }

  • The session belonging to the underlying task.

    Declaration

    Swift

    public let session: NSURLSession

  • The request sent or to be sent to the server.

    Declaration

    Swift

    public var request: NSURLRequest { get }

  • The response received from the server, if any.

    Declaration

    Swift

    public var response: NSHTTPURLResponse? { get }

  • The progress of the request lifecycle.

    Declaration

    Swift

    public var progress: NSProgress? { get }

  • Undocumented

  • Associates an HTTP Basic credential with the request.

    Declaration

    Swift

    public func authenticate(#user: String, password: String) -> Self

    Parameters

    user

    The user.

    password

    The password.

    Return Value

    The request.

  • Associates a specified credential with the request.

    Declaration

    Swift

    public func authenticate(usingCredential credential: NSURLCredential) -> Self

    Parameters

    credential

    The credential.

    Return Value

    The request.

  • Sets a closure to be called periodically during the lifecycle of the request as data is written to or read from the server.

    • For uploads, the progress closure returns the bytes written, total bytes written, and total bytes expected to write.
    • For downloads, the progress closure returns the bytes read, total bytes read, and total bytes expected to write.

    Declaration

    Swift

    public func progress(closure: ((Int64, Int64, Int64) -> Void)? = default) -> Self

    Parameters

    closure

    The code to be executed periodically during the lifecycle of the request.

    Return Value

    The request.

  • Creates a response serializer that returns the associated data as-is.

    Declaration

    Swift

    public class func responseDataSerializer() -> Serializer

    Return Value

    A data response serializer.

  • Adds a handler to be called once the request has finished.

    Declaration

    Swift

    public func response(completionHandler: (NSURLRequest, NSHTTPURLResponse?, AnyObject?, NSError?) -> Void) -> Self

    Parameters

    completionHandler

    The code to be executed once the request has finished.

    Return Value

    The request.

  • Adds a handler to be called once the request has finished.

    Declaration

    Swift

    public func response(queue: dispatch_queue_t? = default, serializer: Serializer, completionHandler: (NSURLRequest, NSHTTPURLResponse?, AnyObject?, NSError?) -> Void) -> Self

    Parameters

    queue

    The queue on which the completion handler is dispatched.

    serializer

    The closure responsible for serializing the request, response, and data.

    completionHandler

    The code to be executed once the request has finished.

    Return Value

    The request.

  • Suspends the request.

    Declaration

    Swift

    public func suspend()

  • Resumes the request.

    Declaration

    Swift

    public func resume()

  • Cancels the request.

    Declaration

    Swift

    public func cancel()

  • Undocumented

  • Undocumented