REST Client Example in Ruby

REST Client – simple DSL for accessing HTTP and REST resources

A simple HTTP and REST client for Ruby, inspired by the Sinatra’s microframework style of specifying actions: get, put, post, delete.

I found this Ruby-Gem very useful while building App. so i will describe here how to use REST Client in Ruby

Simple example for REST Client POST Request.

require 'rest_client'


res=RestClient.post 'http://localhost:8080/wm/test/json', params.to_json, :content_type => :json, :accept => :json
result = JSON.parse(res)
return result.to_json

above example send post request to my local server, which takes few parameters in form of json and

result.to_json

return output in form of JSON.

likewise, you can use any method GET,PUT,DELETE.

Hope you’ll like dis 🙂

Advertisements