Created
October 7, 2013 01:14
-
-
Save Stuk/6861192 to your computer and use it in GitHub Desktop.
Parsing POST requests in Joey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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