Crest::Resource
A class that can be instantiated for access to a RESTful resource, including authentication, proxy and logging.
Simple example:
resource = Crest::Resource.new("https://httpbin.org/get")
response = resource.get
Block style:
resource = Crest::Resource.new("http://httpbin.org") do |res|
res.headers.merge!({"foo" => "bar"})
end
response = resource["/headers"].get
With HTTP basic authentication:
resource = Crest::Resource.new("https://httpbin.org/get", user: "user", password: "password")
Use the [] syntax to allocate subresources:
resource = Crest::Resource.new("https://httpbin.org")
resource["/get"].get
You can pass advanced parameters like default params, headers, or cookies:
resource = Crest::Resource.new(
"https://httpbin.org",
params: {"key" => "key"},
headers: {"Content-Type" => "application/json"},
cookies: {"lang"=> "ua"}
)
response = response["/post"].post(
form: {:height => 100, "width" => "100"},
params: {:secret => "secret"},
cookies: {"locale"=> "en_US"}
)
If you want to stream the data from the response you can pass a block:
resource = Crest::Resource.new("http://httpbin.org")
resource["/stream/5"].get do |response|
while line = response.body_io.gets
puts line
end
end
Constructors
Instance methods
Execute a DELETE request and returns a Crest::Response.
Execute a DELETE request and returns a Crest::Response.
Execute a DELETE request and and yields the Crest::Response to the block.
Execute a DELETE request and and yields the Crest::Response to the block.
Execute a GET request and returns a Crest::Response.
Execute a GET request and returns a Crest::Response.
Execute a GET request and and yields the Crest::Response to the block.
Execute a GET request and and yields the Crest::Response to the block.
Execute a HEAD request and returns a Crest::Response.
Execute a HEAD request and returns a Crest::Response.
Execute a HEAD request and and yields the Crest::Response to the block.
Execute a HEAD request and and yields the Crest::Response to the block.
Execute a OPTIONS request and returns a Crest::Response.
Execute a OPTIONS request and returns a Crest::Response.
Execute a OPTIONS request and and yields the Crest::Response to the block.
Execute a OPTIONS request and and yields the Crest::Response to the block.
Execute a PATCH request and returns a Crest::Response.
Execute a PATCH request and returns a Crest::Response.
Execute a PATCH request and and yields the Crest::Response to the block.
Execute a PATCH request and and yields the Crest::Response to the block.
Execute a POST request and returns a Crest::Response.
Execute a POST request and returns a Crest::Response.
Execute a POST request and and yields the Crest::Response to the block.
Execute a POST request and and yields the Crest::Response to the block.
Execute a PUT request and returns a Crest::Response.
Execute a PUT request and returns a Crest::Response.
Execute a PUT request and and yields the Crest::Response to the block.
Execute a PUT request and and yields the Crest::Response to the block.