REST Client Example in Ruby
Asked Answered
K

2

12

Can anyone explain me with an example, by using REST Client to do GET/POST/PUT operations in a Rest web service?

In POST/PUT, using REST Client, need to pass the whole xml body to do POST/PUT operations.

For example, Using REST Client

I need to get the content of a service using,

      RESTClient.get(url)

POST an xml to an url:

      RESTClient.post(url,entirexml)

PUT an xml to an URL:

      RESTClient.put(url,entirexml)

DELETE using REST CLIENT.

Can anyone help me with examples for all the REST Client HTTP METHODS with example?

I need to send the whole XML along with namespace to a rest service using PUT/POST operations of REST Client.

If anyone have examples on this, kindly post then please.

Kab answered 9/12, 2011 at 22:18 Comment(1)
Please visit here, simple example of REST Client webdevsurya.wordpress.com/2014/03/18/…Hadleigh
C
17
require 'rest-client'

RestClient.get 'http://example.com/resource', {:params => {:id => 50, 'foo' => 'bar'}}

RestClient.get 'http://example.com/resource'

xml = '<xml><foo>bar</foo><bar>foo</bar></xml>'

RestClient.post 'http://example.com/resource', xml , {:content_type => :xml}

RestClient.put 'http://example.com/resource', xml , {:content_type => :xml}

RestClient.delete 'http://example.com/resource'

See more examples and documentation at https://github.com/rest-client/rest-client

Camaraderie answered 16/11, 2012 at 2:43 Comment(2)
require 'rest-client'Incondite
Note that rest-client project appears to be abandoned with last commit in 2017-09-20.Drudge
F
10

The Readme file at the git site for the rest-client gem has a whole bunch of examples of how to do requests, include parameters, etc.

I'd start with that.

If there are specific things that are not working, then it generally helps to post the code you've tried that you think SHOULD be working, and then it's usually easier for people to tell where you are going wrong.

Fontes answered 11/1, 2012 at 0:30 Comment(3)
Note that rest-client project appears to be abandoned with last commit in 2017-09-20.Drudge
given that not much has changed in the land of making and handling REST requests, I would not necessarily take a lack of new commits as the project being abandoned. (it could simply be that it is working well as it is, with no need for new features.) Now, if bugs reports are not being responded to, or pull requests for fixes to outstanding bugs are being ignored, then I would be a lot more concerned.Fontes
It also has 57 waiting pull requests and issues without a response (I see no important bugs reports so far). It is usable and useful but I am starting to look for an alternative.Drudge

© 2022 - 2024 — McMap. All rights reserved.