JSON body #3

Merged
1 commit merged into from Jan 30, 2011

Projects

None yet

2 participants

@Stanley
Contributor
Stanley commented Jan 29, 2011

Hi,
For easier POST and PUT request with body I automatically stringify objects to JSON and add application/json content-type.

Stan

@mikeal
Member
mikeal commented Jan 29, 2011

I'm going to stew on this a little.

I want to keep the interface as low level as possible. This is very useful but I'm concerned that this might lead to a feature that decodes JSON based on the content-type which I really don't want to do.

Also, is it ok to assume JSON for an object as body? What about multipart/form-data? I've also dealt with some annoying APIs that break when you use the proper content type which makes me wearing of adding it automatically.

What if, rather than add assumptions to different object types for body, we add a json option.

request.post({uri:'http://site.com/api', json:{_id:"asdfasdf"}, function () {})

This would also make expanding to additional form post types a lot more straight forward.

Thoughts?

@Stanley
Contributor
Stanley commented Jan 29, 2011

I agree. I should not have assumed content-type.
My motivation was that is was very difficult to track a bug which was caused by an object passed to body. I think this option should allow only strings and throw an error otherwise.

I like json as a separate option. I'll fix that tomorrow.

@mikeal
Member
mikeal commented Jan 29, 2011

Good idea, throwing on bad types with a nice error would be much better and lead to less confusion.

@Stanley
Contributor
Stanley commented Jan 30, 2011

Ok. I fixed it, but I don't know how to add extra commits to this pull request.

@mikeal
Member
mikeal commented Jan 30, 2011

The pull request follows the branch you originally did it for :)

I'll check this out today.

@mikeal
Member
mikeal commented Jan 30, 2011

Hrm... it's not following the branch, maybe that's only when you have a topic branch.

I'll just create a local branch so i can get a branch diff, I'm going to move specs in to tests and make a few other style changes so if you have work that isn't pushed please ping me on irc, I'm mikeal in #node.js on freenode.

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