0

I have this cURL that works fine running from terminal but I need it to be dynamic so I need to make this call from my model.

curl -XPUT -H "content-type:application/json" http://localhost:8098/riak/demo2 -d '{"props":{"precommit":[{"mod":"riak_search_kv_hook","fun":"precommit"}]}}'

This is what I get so far but it is not working, there are no errors and the response is empty. I don't expect anything to be returned, but this should create a new Riak bucket and it doesn't. I have tested, as I said, on my terminal and it works fine, it creates the bucket as expected.

require "net/http"
require "uri"

uri = URI.parse("http://localhost:8098/riak/dg1_logs")

http = Net::HTTP.new(uri.host, uri.port)

request = Net::HTTP::Post.new(uri.request_uri)
request.content_type = "application/json"
request.body = '{"props":{"precommit":[{"mod":"riak_search_kv_hook","fun":"precommit"}]}}'

response = http.request(request)

p response.body

More details

I'm using Riak and I need to enable the Riak Search on my client bucket and it is possible only running this cURL. I need to make it dynamic so when my client creates a new account, I already make his buckets able to Search

I'm using Ruby 1.9.3

1 Answers1

1

I think the problem might be that in the curl example you use HTTP PUT and POST in the ruby example.

By the way you would save yourself some pain if you would have used something like RestClient - way easier to work with than net/http API.

And finally, I don't think it's a good idea to make HTTP requests from a model (assuming you mean AR model), you should probably create a separated object to take care of it for you.

Jiří Pospíšil
  • 14,296
  • 2
  • 41
  • 52