class

Crest::Resource

Inherits Reference < Object

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

new(url : String, **args)

When block is not given.

Source

Instance methods

[](suburl)
Source
close(*args, **options)
Source
close(*args, **options, &)
Source
close_connection
Source
closed?
Source
connect_timeout
Source
cookies
Source
delete(suburl : String | Nil = nil, form = {} of String => String, *, headers = {} of String => String, params = {} of String => String, cookies = {} of String => String) : Crest::Response

Execute a DELETE request and returns a Crest::Response.

Source
delete(form = {} of String => String, **args) : Crest::Response

Execute a DELETE request and returns a Crest::Response.

Source
delete(suburl : String | Nil = nil, form = {} of String => String, *, headers = {} of String => String, params = {} of String => String, cookies = {} of String => String, &block : Crest::Response -> ) : Nil

Execute a DELETE request and and yields the Crest::Response to the block.

Source
delete(form = {} of String => String, **args, &block : Crest::Response -> ) : Nil

Execute a DELETE request and and yields the Crest::Response to the block.

Source
get(suburl : String | Nil = nil, form = {} of String => String, *, headers = {} of String => String, params = {} of String => String, cookies = {} of String => String) : Crest::Response

Execute a GET request and returns a Crest::Response.

Source
get(form = {} of String => String, **args) : Crest::Response

Execute a GET request and returns a Crest::Response.

Source
get(suburl : String | Nil = nil, form = {} of String => String, *, headers = {} of String => String, params = {} of String => String, cookies = {} of String => String, &block : Crest::Response -> ) : Nil

Execute a GET request and and yields the Crest::Response to the block.

Source
get(form = {} of String => String, **args, &block : Crest::Response -> ) : Nil

Execute a GET request and and yields the Crest::Response to the block.

Source
handle_errors
Source
head(suburl : String | Nil = nil, form = {} of String => String, *, headers = {} of String => String, params = {} of String => String, cookies = {} of String => String) : Crest::Response

Execute a HEAD request and returns a Crest::Response.

Source
head(form = {} of String => String, **args) : Crest::Response

Execute a HEAD request and returns a Crest::Response.

Source
head(suburl : String | Nil = nil, form = {} of String => String, *, headers = {} of String => String, params = {} of String => String, cookies = {} of String => String, &block : Crest::Response -> ) : Nil

Execute a HEAD request and and yields the Crest::Response to the block.

Source
head(form = {} of String => String, **args, &block : Crest::Response -> ) : Nil

Execute a HEAD request and and yields the Crest::Response to the block.

Source
headers
Source
http_client
Source
json
Source
logger
Source
logging
Source
options(suburl : String | Nil = nil, form = {} of String => String, *, headers = {} of String => String, params = {} of String => String, cookies = {} of String => String) : Crest::Response

Execute a OPTIONS request and returns a Crest::Response.

Source
options(form = {} of String => String, **args) : Crest::Response

Execute a OPTIONS request and returns a Crest::Response.

Source
options(suburl : String | Nil = nil, form = {} of String => String, *, headers = {} of String => String, params = {} of String => String, cookies = {} of String => String, &block : Crest::Response -> ) : Nil

Execute a OPTIONS request and and yields the Crest::Response to the block.

Source
options(form = {} of String => String, **args, &block : Crest::Response -> ) : Nil

Execute a OPTIONS request and and yields the Crest::Response to the block.

Source
p_addr
Source
p_pass
Source
p_port
Source
p_user
Source
params
Source
password
Source
patch(suburl : String | Nil = nil, form = {} of String => String, *, headers = {} of String => String, params = {} of String => String, cookies = {} of String => String) : Crest::Response

Execute a PATCH request and returns a Crest::Response.

Source
patch(form = {} of String => String, **args) : Crest::Response

Execute a PATCH request and returns a Crest::Response.

Source
patch(suburl : String | Nil = nil, form = {} of String => String, *, headers = {} of String => String, params = {} of String => String, cookies = {} of String => String, &block : Crest::Response -> ) : Nil

Execute a PATCH request and and yields the Crest::Response to the block.

Source
patch(form = {} of String => String, **args, &block : Crest::Response -> ) : Nil

Execute a PATCH request and and yields the Crest::Response to the block.

Source
post(suburl : String | Nil = nil, form = {} of String => String, *, headers = {} of String => String, params = {} of String => String, cookies = {} of String => String) : Crest::Response

Execute a POST request and returns a Crest::Response.

Source
post(form = {} of String => String, **args) : Crest::Response

Execute a POST request and returns a Crest::Response.

Source
post(suburl : String | Nil = nil, form = {} of String => String, *, headers = {} of String => String, params = {} of String => String, cookies = {} of String => String, &block : Crest::Response -> ) : Nil

Execute a POST request and and yields the Crest::Response to the block.

Source
post(form = {} of String => String, **args, &block : Crest::Response -> ) : Nil

Execute a POST request and and yields the Crest::Response to the block.

Source
put(suburl : String | Nil = nil, form = {} of String => String, *, headers = {} of String => String, params = {} of String => String, cookies = {} of String => String) : Crest::Response

Execute a PUT request and returns a Crest::Response.

Source
put(form = {} of String => String, **args) : Crest::Response

Execute a PUT request and returns a Crest::Response.

Source
put(suburl : String | Nil = nil, form = {} of String => String, *, headers = {} of String => String, params = {} of String => String, cookies = {} of String => String, &block : Crest::Response -> ) : Nil

Execute a PUT request and and yields the Crest::Response to the block.

Source
put(form = {} of String => String, **args, &block : Crest::Response -> ) : Nil

Execute a PUT request and and yields the Crest::Response to the block.

Source
read_timeout
Source
stream_multipart
Source
user
Source
user_agent
Source
write_timeout
Source