-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How send request get with params ? #22
Comments
Hey @ngocdtph03070, Could you provide the part of the code where you build the request so I can check it out ? Cheers, |
@s4cha Yes , Thank for reply var parameters = ["where":["coordinate":nearSphere],"include":"category,user"] |
the param string generated by ws is which is whereas the one you pasted above generates
which should be This is indeed an encoding issue. The dictionary is not automatically translated into JSON, which is normal, I guess. Something like this would produce the desired output func test() -> Promise<JSON> {
let categoryJson = "{\"category\":{\"$inQuery\":{\"where\":{\"objectId\":\"GPZPzdsk0I\"},\"className\":\"Category\"}},\"coordinate\":{\"$nearSphere\":{\"__type\":\"GeoPoint\",\"latitude\":20.286312208425457,\"longitude\":106.30682822629947}, \"$maxDistanceInKilometers\": 15.0 }}"
return ws.get("/classes/Place", params:[
"where": categoryJson,
"include":"category,user"])
} There is no helper method on our side at the moment to transform a [String:Any] into a JSON string, because we never had the case. This surely looks like something we'd like to add to our roadmap though :) Cheers, |
@s4cha Thank you I try code for format and talk for you :) |
@ngocdtph03070 What technology are you using on the backend side ? I am curious :) |
@s4cha i use parse server platform but i want rest api not use sdk |
Ahh cool! thanks for the info :) |
@s4cha thank you for framework it is good . |
@ngocdtph03070 Does your call work now ? |
Yes it run :) |
@ngocdtph03070 I guess you already have a helper but here is a way to avoid having to hardcode and escape the JSON string ourselves. func dictionaryToJSONString(_ d:[String : Any]) -> String {
if let data = try? JSONSerialization.data(withJSONObject: d), let s = String(data: data, encoding: String.Encoding.utf8) {
return s
} else {
return ""
}
} For a given JSON structure {
"category": {
"$inQuery": {
"where": {
"objectId": "GPZPzdsk0I"
},
"className": "Category"
}
},
"coordinate": {
"$nearSphere": {
"__type": "GeoPoint",
"latitude": 20.286312208425457,
"longitude": 106.30682822629947
},
"$maxDistanceInKilometers": 15.0
}
} Write it as a native dictionary and use helper method to get back the JSON string func test() -> Promise<Void> {
let dic:[String : Any] = [
"category": [
"$inQuery": [
"where": [
"objectId" : "GPZPzdsk0I"
],
"className" : "Category"
]
],
"coordinate" : [
"$nearSphere": [
"__type": "GeoPoint",
"latitude": 20.286312208425457,
"longitude": 106.30682822629947
],
"$maxDistanceInKilometers": 15.0
]
]
let jsonString = dictionaryToJSONString(dic)
return ws.get("/api/classes/Place",
params:["where" : jsonString,
"include": "category,user"])
} Let me know what you think, Have an awesome day ! |
Yes it good instead of fix string json func convert dictionnary to string json Thank you |
I think ws framework should support http request param body |
We are very open to suggestions, could you elaborate on how the api would look like ? |
As Parse server when i rest api in case post data success with httpBody raw format json . |
I have a request get with format http://192.168.1.4:1337/api/classes/Place?where={"category":{"$inQuery":{"where":{"objectId":"GPZPzdsk0I"},"className":"Category"}},"coordinate":{"$nearSphere":{"__type":"GeoPoint","latitude":20.286312208425457,"longitude":106.30682822629947}, "$maxDistanceInKilometers": 15.0 }}&include=category,user
and test api on post man is ok as I convert to params in swift is can not get.I think url encoding not right. You can help me ?
The text was updated successfully, but these errors were encountered: