Skip to content

Instantly share code, notes, and snippets.

@Stuk
Created October 7, 2013 01:14
Show Gist options
  • Save Stuk/6861192 to your computer and use it in GitHub Desktop.
Save Stuk/6861192 to your computer and use it in GitHub Desktop.
Parsing POST requests in Joey
var joey = require("joey");
// Uses qs https://npmjs.org/package/qs
var qs = require("qs");
joey
.log()
.error()
.favicon()
.route(function ($) {
// A form to use
$("")
.method("GET")
.contentType("text/html")
.content('<form method="post" action="save"><input name="thing"><input name="another"><input type="submit"></form>');
$("save")
.method("POST")
.contentType("text/plain")
.contentApp(function (request) {
return request.body.read()
.then(function (buffer) {
// convert buffer to string
var content = buffer.toString("utf8");
// parse
console.log(qs.parse(content));
});
});
})
.listen(8082)
.then(function () {
console.log("Listening on http://localhost:8082");
})
.done();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment