Forum: Ruby sending a payload with JSON and REST

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ee6fb5cad9d1b269f1dcbb5a76c9d760?d=identicon&s=25 Moutalib Abdel (jarh)
on 2014-08-10 13:17
Hello all,

I'm new to the JSON and REST modules, and i'm struggling to send the
following payload information as a post method:

url: 'http://site.local/trim/v1/config/login'
method: post
request header: Content-Type:xxxx/xxx+json
require 'JSON'
require 'rest-client'

post =, {:params => {login => 'username','admin',
'password','secret'}}, {"Content-Type" => "application/tribapte" })
puts post.args[:payload][:params]

The problem is that the ':params' are not matching the ruby hash
structure, so this code will never run successful.

Hopefully someone can guide me trough the process
of successfully post the payload as mentioned above.

Thanks in advance!

4a65f01f7ece0b720bdb0de3c3db089e?d=identicon&s=25 Dansei Yuuki (blutorange)
on 2014-08-10 18:15
> def, payload, headers={}, &block)

Does this work?

> url = ''
> payload = { 'login' => {'username' => 'admin', 'password' => 'secret'}}
> initheader = { 'Content-Type' => 'xxxx/xxx+json' }
>, payload, initheader)

Generating the json payload yourself should work as well

> encoded = JSON.generate(payload)
>, encoded, initheader)
Ee6fb5cad9d1b269f1dcbb5a76c9d760?d=identicon&s=25 Moutalib Abdel (jarh)
on 2014-08-10 21:44
Thanks Dansei that was indeed very helpful!

This topic is locked and can not be replied to.