class Crest::Resource
- Crest::Resource
- Reference
- Object
Overview
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
Defined in:
crest/resource.crConstructors
- .new(url : String, *, headers : Hash(String, String) = {} of String => String, params = {} of String => String, cookies = {} of String => String, **options, &)
-
.new(url : String, **args)
When block is not given.
Instance Method Summary
- #[](suburl)
- #close(*args, **options)
- #close(*args, **options, &)
- #close_connection : Bool
- #closed?
- #connect_timeout : Float32 | Int32 | Time::Span | Nil
- #cookies : Hash(String, Bool | Float32 | Float64 | IO | Int32 | Int64 | String | Symbol | Nil)
-
#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
. -
#delete(form = {} of String => String, **args) : Crest::Response
Execute a DELETE request and returns a
Crest::Response
. -
#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. -
#delete(form = {} of String => String, **args, &block : Crest::Response -> ) : Nil
Execute a DELETE request and and yields the
Crest::Response
to the block. -
#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
. -
#get(form = {} of String => String, **args) : Crest::Response
Execute a GET request and returns a
Crest::Response
. -
#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. -
#get(form = {} of String => String, **args, &block : Crest::Response -> ) : Nil
Execute a GET request and and yields the
Crest::Response
to the block. - #handle_errors : Bool
-
#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
. -
#head(form = {} of String => String, **args) : Crest::Response
Execute a HEAD request and returns a
Crest::Response
. -
#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. -
#head(form = {} of String => String, **args, &block : Crest::Response -> ) : Nil
Execute a HEAD request and and yields the
Crest::Response
to the block. - #headers : Hash(String, String)
- #http_client : HTTP::Client
- #json : Bool
- #logger : Crest::Logger
- #logging : Bool
-
#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
. -
#options(form = {} of String => String, **args) : Crest::Response
Execute a OPTIONS request and returns a
Crest::Response
. -
#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. -
#options(form = {} of String => String, **args, &block : Crest::Response -> ) : Nil
Execute a OPTIONS request and and yields the
Crest::Response
to the block. - #p_addr : String?
- #p_pass : String?
- #p_port : Int32?
- #p_user : String?
- #params : Hash(String, Bool | Float32 | Float64 | IO | Int32 | Int64 | String | Symbol | Nil)
- #password : String?
-
#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
. -
#patch(form = {} of String => String, **args) : Crest::Response
Execute a PATCH request and returns a
Crest::Response
. -
#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. -
#patch(form = {} of String => String, **args, &block : Crest::Response -> ) : Nil
Execute a PATCH request and and yields the
Crest::Response
to the block. -
#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
. -
#post(form = {} of String => String, **args) : Crest::Response
Execute a POST request and returns a
Crest::Response
. -
#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. -
#post(form = {} of String => String, **args, &block : Crest::Response -> ) : Nil
Execute a POST request and and yields the
Crest::Response
to the block. -
#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
. -
#put(form = {} of String => String, **args) : Crest::Response
Execute a PUT request and returns a
Crest::Response
. -
#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. -
#put(form = {} of String => String, **args, &block : Crest::Response -> ) : Nil
Execute a PUT request and and yields the
Crest::Response
to the block. - #read_timeout : Float32 | Int32 | Time::Span | Nil
- #url : String
- #user : String?
- #user_agent : String?
- #write_timeout : Float32 | Int32 | Time::Span | Nil
Constructor Detail
Instance Method Detail
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.