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
or #headers
:
resource = Crest::Resource.new(
"https://httpbin.org",
params: {"key" => "key"},
headers: {"Content-Type" => "application/json"}
)
response = response["/post"].post(
form: {:height => 100, "width" => "100"},
params: {:secret => "secret"}
)
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 : Params = {} 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?(*args, **options)
- #closed?(*args, **options, &)
-
#delete(suburl : String | Nil = nil, *, form = {} of String => String, headers = {} of String => String, params = {} of String => String) : 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, &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) : 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, &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) : 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, &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
- #logger : Crest::Logger
- #logging : Bool
-
#options(suburl : String | Nil = nil, *, form = {} of String => String, headers = {} of String => String, params = {} of String => String) : 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, &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 | Symbol, Int32 | String) | Hash(String, Int32 | String) | Hash(String, Int32) | Hash(String, String) | Hash(Symbol, Int32 | String) | Hash(Symbol, Int32) | Hash(Symbol, String)
- #password : String?
-
#patch(suburl : String | Nil = nil, *, form = {} of String => String, headers = {} of String => String, params = {} of String => String) : 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, &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) : 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, &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) : 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, &block : Crest::Response -> ) : Nil
Execute a PUT request and and yields the
Crest::Response
to the block. - #url : String
- #user : String?
Constructor Detail
Instance Method Detail
Execute a DELETE request and returns a Crest::Response
.
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 and yields the Crest::Response
to the block.
Execute a HEAD request and returns a Crest::Response
.
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 and yields the Crest::Response
to the block.
Execute a PATCH request and returns a Crest::Response
.
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 and yields the Crest::Response
to the block.
Execute a PUT request and returns a Crest::Response
.
Execute a PUT request and and yields the Crest::Response
to the block.