Skip to content
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

Flatten :form hash? #2

Closed
jjb opened this issue Nov 17, 2011 · 2 comments
Closed

Flatten :form hash? #2

jjb opened this issue Nov 17, 2011 · 2 comments

Comments

@jjb
Copy link

jjb commented Nov 17, 2011

Hi -- I love the library.

What do you think about putting the POST vars hash at the top level instead of pointing at it with :form? There's nothing else in that options hash anyway, and also the word "form" kind of bothers me, since that's device-specific and in this case it's clearly not a form :)

Http.post "http://example.com/resource", {:foo => "42"}
@tarcieri
Copy link
Member

:form is there to indicate what you pass to it should be sent encoded as "application/x-www-form-urlencoded", and as far as HTTP is concerned, it is sending a form. This is what Net::HTTP originally tried to disambiguate it with a separate method, #post_form.

You can post other things besides forms. For example you should be able to post JSON with:

Http.post "http://example.com/resource", :json => {:foo => "42"}

This would encode the Ruby hash as a JSON object and post it with the type "application/json"

Without toplevel options, how do you disambiguate how the Ruby object should be encoded?

@jjb
Copy link
Author

jjb commented Nov 17, 2011

Ah ha, okay -- so I was wrong about it not indicating anything (should have looked at the code first...) -- I guess I assumed that was explicitly set in the headers at the user's discretion -- nice to see that it's automatic. I like the library even more now. This should be in the ruby 2 standard library :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants