0
votes

I need to send a login request to the API of my app, I don't code the API, someone is doing that for us, so I use postman to test the request and with Postman I do this :

URL : {{dev}}/customer/login-mock

Body / x-www-form-urlencoded : 

key = toto / value = toto
key = toto / value = toto

With this I get a response.

But I don't know how to achieve it with Alamofire .. I'm a bit lost, and all the tutorial I'm seeing are using url params to send parameters to their api.

I which I could use a func like :

RequestManager.request(.POST, "customer/login-mock", body: [username: "toto", password: "toto"])

class RequestManager: NSObject {
    request(method, url, body) {
      Alamofire.request(someRequest).responseJSON{response in ....}
    }

}

Thanks for your help !

1

1 Answers

0
votes

Use this :-

 Alamofire.request(.GET, query, parameters : param, headers : headers).responseJSON { (response) -> Void in
                switch response.result
                {
                case .Success: //Success
                    if let value = response.result.value
                    {
                        completion(result: value, error: "")
                        print(value)
                    }
                case .Failure(let error): //error
                    completion(result: "", error: error)
                }
            }