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
post request body #22
Comments
Vapor currently only supports form encoded data. Issue #28 covers supporting JSON requests. |
@tannernelson Cool, in the meantime, here's two different examples that work: In case it helps, these are both functioning for me: extension Request {
public var jsonBody: Any? {
var bytes = body
let data = NSData(bytes: &bytes, length: body.count)
return try? NSJSONSerialization
.JSONObjectWithData(data, options: .AllowFragments)
}
} Or w/ pure json dependency:
extension Request {
public var jsonBody: Json? {
return try? Json.deserialize(body)
}
} |
Does that compile on Ubuntu 14, 15, and OS X? If so, you should submit that as a PR. |
They both work on Heroku box, but the I think until Foundation adds official support, it might be worth using, or pointing to a 3rd party dependency. The PureJson version above runs on all instances and in my opinion, is a better way to deal with Json. If you're interested in that, I can make a pull that includes the dependency. It's a little slower than NSJSON, but you also get the added benefit of being able to return: return json.serialize(.PrettyPrint) Which serializes more effectively |
The NSJSON from Foundation won't work because it relies on the automatic casting of any So I think a dependency makes sense for serialization on Linux. If Apple does decide to include Foundation support at some point it can be removed. |
When receiving a JSON request, I expected the
request.data
to include the keys and values, but instead it's a json string key and value that are identical, ie:["{\"hello\":\"world\"}" : "{\"hello\":\"world\"}"]
The text was updated successfully, but these errors were encountered: