0

I am trying to query data from my Deployd API with alamofire. How is it possible to do a comparison in a request. I have something like:

let parameters = ["number": ["gt": 3]]
 Manager.sharedInstance.request(.GET, "http://localhost:2403/collections", parameters: parameters).responseJSON { (request, response, result) -> Void in
            print(result.isSuccess)
            print(result.data)
        }

But the result is empty. In my dashboard i have a number column with the values: 1,2,3 and 4. So the response should return me the rows with the number 4.

Any ideas? Thank

Ian Cassar
  • 23
  • 6
emoleumassi
  • 4,881
  • 13
  • 67
  • 93

1 Answers1

0

You need to extract the value instead of the data. In Alamofire 2.0, the data is only available in a .Failure case. This has all been redesigned in Alamofire 3.0 which leverages a Response object instead.

let parameters = ["number": ["gt": 3]]
let URLString = "http://localhost:2403/collections"

Manager.sharedInstance.request(.GET, URLString, parameters: parameters)
    .responseJSON { (request, response, result) -> Void in
        print(result.isSuccess)
        print(result.data)
        print("JSON: \(result.value)")
        print("Error: \(result.error)")
    }
cnoon
  • 16,575
  • 7
  • 58
  • 66
  • it didn't work. The console print nothing, JSON: Optional(()) – emoleumassi Oct 05 '15 at 15:25
  • Then you need to print out the `error`. That should give you more info. Additionally, I just noticed that you are using a `.GET` when it would make MUCH more sense to be doing a `.PUT` or `.POST`. – cnoon Oct 05 '15 at 15:27
  • With .PUT or .POST? The documentation recommend to do it with GET. See hier http://docs.deployd.com/docs/collections/reference/querying-collections.html#s-$skip-1416. I try it with POST but i get an error: JSON: Optional({ message = "must provide id to update an object"; status = 400; }). With GET, the error is nil – emoleumassi Oct 05 '15 at 15:47
  • Your parameters are just a bit odd for a `GET`, that's the reason I wondered if you were using the wrong HTTP method. If your error is nil, then you need to try to figure out what's coming back in the data. You could convert it to a string to print it out or use the responseString method. – cnoon Oct 06 '15 at 03:33