micha / resty

Little command line REST client that you can use in pipelines (bash or zsh).
MIT License
2.65k stars 143 forks source link

Cannot POST or PUT JSON data without Content-type Header #56

Closed rajaravivarma-r closed 7 years ago

rajaravivarma-r commented 9 years ago

As per the following example, given in the README POST /blogs.json '{"title" : "new post", "body" : "This is the new new."}' it should work without setting Content-type Header. But it doesn't.

Example: When the POST request is as follows POST /creator/files.json '{ "attributes": [ {"title": "New Book" } ] }' This is how Rails receives the parameter Parameters: {"{ \"attributes\": "=>{" {\"title\": \"New Book\" } "=>{" }"=>nil}}} The scenario remains the same when the input is read from a file or pipe echo '{ "attributes": [ {"title": "New Book" } ] }' | POST /creator/files.json

But when the POST request is made with Content-type as follows POST /creator/files.json '{ "attributes": [ {"title": "New Book" } ] }' -H 'Content-type: application/json' Rails receives the parameters properly as, {"attributes"=>[{"title"=>"New Book"}]}

Please add Content-type: application/json Header automatically if the URL ends with .json. Though I am not sure if this is applicable only for Rails.

AdrieanKhisbe commented 9 years ago

Good idea, will do.

was already considering adding --json flag as alias of `-H 'Content-type: application/json'``

Not that you can place -H 'Content-type: application/json' in your config file so you don't have to precise it over and other.

akhy commented 8 years ago

+1 for --json

AdrieanKhisbe commented 8 years ago

@akhyrul haha, comming soon. :) I restarted to hack around. Trying to reset up the test infrastructure before to go forward: cf https://github.com/AdrieanKhisbe/resty/tree/test-with-cucumber

AdrieanKhisbe commented 7 years ago

I intended to do it, once I complete the major release. sorry for the delay

AdrieanKhisbe commented 7 years ago

Done in c4c739e, will land with the very soon 3.0 release.

A --json with set both Accept and Content-Type to json

closing the issue.