Post JSON with BubbleWrap

404 views
Skip to first unread message

Jonathan Silverman

unread,
Jul 3, 2012, 2:35:39 AM7/3/12
to bubbl...@googlegroups.com
How do you do this? It seems to want to use Form Encoding by default. :D

Thanks,
jsilver

Marin Usalj

unread,
Jul 3, 2012, 4:58:49 AM7/3/12
to bubbl...@googlegroups.com
I've made the HTTP testing app so you can confirm what's coming to the web server:

However, it depends on how do you want to submit the json (as a string or data?).


This is how I've made it:


(main)> sample_json = BW::JSON.generate({ name: 'marin' })
=> "{\"name\":\"marin\"}"

(main)> BW::HTTP.post('http://bw.dev', payload: {json: sample_json}) {|r| p BW::JSON.parse r.body}

=> #<BubbleWrap::HTTP::Query:0xe275ba0 @method="POST" @delegator=#<Proc:0xe27d690> @payload={:json=>"{\"name\":\"marin\"}"} @files=nil @boundary="F1F893C1-7D4C-478F-9716-7E6C2C401E8C" @credentials={:username=>"", :password=>""} @timeout=30.0 @headers={"Content-Type"=>"multipart/form-data; boundary=F1F893C1-7D4C-478F-9716-7E6C2C401E8C"} @cache_policy=0 @options={} @response=#<BubbleWrap::HTTP::Response:0xe275a80> @url=#<NSURL:0xe27db20> @body=#<NSConcreteMutableData:0xe27ddb0> @request=#<NSMutableURLRequest:0xe27da70> @connection=#<NSURLConnection:0xe27fad0>>

(main)> {"method"=>"POST", "json"=>"{\"name\":\"marin\"}"}


This is the BubbleWrap from github/master, not the one from ruby gems (it got changed a bit).

Marin Usalj

unread,
Jul 3, 2012, 6:40:53 AM7/3/12
to bubbl...@googlegroups.com
Here, it's deployed on the web,. you can test any HTTP(get,post,put,delete,head,upload) requests with it.

Example:

Jonathan Silverman

unread,
Aug 2, 2012, 3:25:03 PM8/2/12
to bubbl...@googlegroups.com
Mneorr, thanks. Didn't see this message for a while.

Does this work with PUT too?

Marin Usalj

unread,
Aug 5, 2012, 6:40:14 AM8/5/12
to bubbl...@googlegroups.com
It should.

Here's the sample:

BW::HTTP.put('http://arest.us/json', payload: { json: BW::JSON.generate({ name: 'john', surname: 'doe'}) } ) do |response|                                                                                                                        puts response.body.to_str
end

Jonathan Silverman

unread,
Oct 13, 2012, 9:28:01 PM10/13/12
to bubbl...@googlegroups.com
Thanks
Reply all
Reply to author
Forward
0 new messages