Use qs stringify for post body #46

Open
wants to merge 3 commits into
from

Projects

None yet

2 participants

@bantic
bantic commented Jun 29, 2011

This uses qs.stringify to turn options.body into a string if it is an object in Browser.post. I am not sure the best way to determine if a variable is an object so I used Object.prototype.toString.call(options.body) (which I saw used in node-querystring (https://github.com/visionmedia/node-querystring/blob/master/lib/querystring.js#L17).

@tj tj commented on the diff Jun 29, 2011
lib/browser.js
@@ -157,6 +158,9 @@ Browser.prototype.request = function(method, path, options, fn, saveHistory){
// Request body
if (options.body) {
+ if ('[object Object]' === Object.prototype.toString.call(options.body)) {
+ options.body = qs.stringify(options.body);
@tj
tj Jun 29, 2011 LearnBoost member

would be nice to abstract these out a little with an object mapping content types to functions say something like:

exports.stringify['application/x-www-form-urlencoded'] = qs.stringify

so then we could have application/json etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment