Walker
Walker

Reputation: 1147

swift 3 alamofire - get request gives response serialization failed

I'm using devise on ruby on rails for authentication. Taking it one step at a time, I have disabled the cookie authentication in order to test retrieving results prior to authentication.

If I go to my browser and navigate to the url that Alamofire is visiting, I get results in JSON format like this :

{"id":250,"name":null,"username":"walker","bio":null,"gender":null,"birth_date":null,"profile_image_url":null}

I'm requesting the alamofire request like this:

  Alamofire.request(requestPath, method: .get, parameters: [:], encoding: JSONEncoding.default, headers: [:]).responseJSON { (response) in

            if (response.result.isFailure) {


                completion(false, "")

            } else {

                if let result = response.result.value {
                    completion(true, result)
                }

            }
        }

This is all inside of another method which simply provides with a completion handler as you can see inside of the completion handler of the Alamofire request.

I get an error every single time.

The error says:

responseSerializationFailed : ResponseSerializationFailureReason

What am i doing wrong?

Upvotes: 1

Views: 2280

Answers (1)

Mohammed Riyadh
Mohammed Riyadh

Reputation: 1019

This error indicates that your response is not a JSON formatted data(or something wrong with your API Response), try to use something like post man to check your API response and to make sure every thing is ok before requesting with to swift

Upvotes: 2

Related Questions