IOS http POST using Alamofire


I need some help using Alamofire to do a POST to a web page using a username/password throug an API from Twilio.

I have used SwiftRequest from GitHub before, but that doesn't support Swift 2.0.

The code I used (using SwiftRequest) was:

        var data = [
            "To" : mobileInput.text as String!,
            "From" : twilioSMSFrom,
            "Body" : String(code) as String

        var swiftRequest = SwiftRequest()"\(twilioUsername)/Messages",
            auth: ["username" : twilioUsername, "password" : twilioPassword],
            data: data,
            callback: {err, response, body in
                if err == nil {
                    println("Success: \(response)")
                } else {
                    println("Error: \(err)")

How can I translate this to use Alamofire instead?

I have tried searching for a solution, but could find any.

Can anybody help me?

Try something like this:

Alamofire.request(.POST, "\(twilioUsername)/Messages", parameters: ["username": twilioUsername, "password" : twilioPassword])
     .responseJSON { response in

         if let JSON = response.result.value {
             print("Did receive JSON data: \(JSON)")
         else {
             print("JSON data is nil.")


You should definitely check their github page -