Module: RestClient
- Defined in:
- lib/vendor/rest-client/lib/rest_client.rb,
lib/vendor/rest-client/lib/rest_client/payload.rb,
lib/vendor/rest-client/lib/rest_client/resource.rb,
lib/vendor/rest-client/lib/rest_client/request_errors.rb
Overview
This module’s static methods are the entry point for using the REST client.
xml = RestClient.get 'http://example.com/resource'
jpg = RestClient.get 'http://example.com/resource', :accept => 'image/jpg'
RestClient.get 'https://user:[email protected]/private/resource'
RestClient.post 'http://example.com/resource', :param1 => 'one'
RestClient.post 'http://example.com/resource', :nested => { :param1 => 'one' }
RestClient.post 'http://example.com/resource', 'the post body', :content_type => 'text/plain'
RestClient.post 'http://example.com/resource.xml', xml_doc
RestClient.put 'http://example.com/resource.pdf', File.read('my.pdf'), :content_type => 'application/pdf'
RestClient.delete 'http://example.com/resource'
For live tests of RestClient, try using rest-test.heroku.com, which echoes back information about the rest call:
>> RestClient.put 'http://rest-test.heroku.com/resource', :foo => 'baz'
=> "PUT http://rest-test.heroku.com/resource with a 7 byte payload, content type application/x-www-form-urlencoded {\"foo\"=>\"baz\"}"
Defined Under Namespace
Modules: Payload
Classes: Exception, Redirect, Request, RequestFailed, RequestTimeout, Resource, ResourceNotFound, ServerBrokeConnection, Unauthorized
Class Method Summary
collapse
-
.delete(url, headers = {}, &b) ⇒ Object
-
.get(url, headers = {}, &b) ⇒ Object
-
.post(url, payload, headers = {}, &b) ⇒ Object
-
.put(url, payload, headers = {}, &b) ⇒ Object
Class Method Details
.delete(url, headers = {}, &b) ⇒ Object
58
59
60
61
62
|
# File 'lib/vendor/rest-client/lib/rest_client.rb', line 58
def self.delete(url, ={}, &b)
Request.execute(:method => :delete,
:url => url,
:headers => , &b)
end
|
.get(url, headers = {}, &b) ⇒ Object
38
39
40
41
42
|
# File 'lib/vendor/rest-client/lib/rest_client.rb', line 38
def self.get(url, ={}, &b)
Request.execute(:method => :get,
:url => url,
:headers => , &b)
end
|
.post(url, payload, headers = {}, &b) ⇒ Object
44
45
46
47
48
49
|
# File 'lib/vendor/rest-client/lib/rest_client.rb', line 44
def self.post(url, payload, ={}, &b)
Request.execute(:method => :post,
:url => url,
:payload => payload,
:headers => , &b)
end
|
.put(url, payload, headers = {}, &b) ⇒ Object
51
52
53
54
55
56
|
# File 'lib/vendor/rest-client/lib/rest_client.rb', line 51
def self.put(url, payload, ={}, &b)
Request.execute(:method => :put,
:url => url,
:payload => payload,
:headers => , &b)
end
|