Search code examples
rubyputrest-client

ruby rest_client put request doesn't work properly


I send PUT request to some service with RestClient gem. I do it like:

RestClient.put('http:/app.com/resource/:id.json', { app_token: 'xxx', resource: { status: 'NNN' }})

But the answer JSON is empty (doesn't return what I need). If I send the request like this:

RestClient.put('http:/app.com/resource/:id.json?app_token=XXX&resource[status]=NNN', {})

then all is OK (JSON is normal). What is wrong with my code? Thanks!


P.S. Log:

1) RestClient.put "http:/app.com/resource/:id.json", "app_token=XXX&resource[status]=NNN", "Accept"=>"/; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"73", "Content-Type"=>"application/x-www-form-urlencoded"

# => 200 OK | application/json 12 bytes (empty JSON)

2) RestClient.put "http:/app.com/resource/:id.json?app_token=XXX&resource[status]=NNN", "Accept"=>"/; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate"

# => 200 OK | application/json 37 bytes (valid JSON)


Solution

  • From doc I think it should be written as:

    RestClient.put('http:/app.com/resource/:id.json', nil,{params: { app_token: 'xxx', resource: { status: 'NNN' }}})
    

    See https://github.com/rest-client/rest-client#query-parameters