Skip to content

Instantly share code, notes, and snippets.

@tareq3
Last active June 7, 2022 12:27
Show Gist options
  • Save tareq3/fb7f2beca0e5465676096fd137be5a4e to your computer and use it in GitHub Desktop.
Save tareq3/fb7f2beca0e5465676096fd137be5a4e to your computer and use it in GitHub Desktop.

Using Alamofire make a quick post call without dto

target payload

   private func loginUser(email:String, pass : String){
        let headers = ["Accept": "application/json",
                       "Content-Type": "application/json"
        ]
        
       // in alamofire payload is params 
        let params = [
            "email": email,
            //this is for nested object
            "password": [
                "value": pass
            ]
            
        ] as [String : Any]
        
        let url = "https://qa.onvirtual.cards/proxy/multi/login_with_password"
        AF.request(url, method: .post, parameters: params, encoding: JSONEncoding.default)
            .validate()
            .responseJSON{(response) in
                print (response)
                switch response.result{
                    case .success:
                        if let json = response.value as? [String:Any] {
                            self.bearerToken = json["token"]  as! String
                            print(json["token"])
                            
                        }
    // value is a simple iOS dictionary of type [String: Any] from which you can extract additional information
                    case .failure(let error):
                        print (error)
                }
            }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment