class Crest::Request
- Crest::Request
- Reference
- Object
Overview
A class that used to make the requests
The result of a Crest::Request
is a Crest::Response
object.
Simple example:
request = Crest::Request.new(:post, "http://httpbin.org/post", {"age" => 27}, params: {:name => "Kurt"})
request.execute
Crest::Request.execute(:post, "http://httpbin.org/post", {"age" => 27}, json: true)
Crest::Request.post("http://httpbin.org/post", {"age" => 27}, json: true)
Block style:
request = Crest::Request.new(:get, "http://httpbin.org/get") do |request|
request.headers.add("foo", "bar")
request.user = "username"
request.password = "password"
end
response = request.execute
Mandatory parameters:
Optional parameters:
#headers
a hash containing the request headers#cookies
a hash containing the request cookiesform
a hash containing form data (or a raw string)params
a hash that represent query params (or a raw string) - a string separated from the preceding part by a question mark (?) and a sequence of attribute–value pairs separated by a delimiter (&).params_encoder
params encoder (default toCrest::FlatParamsEncoder
)#auth
access authentication methodbasic
ordigest
(default tobasic
)#user
and#password
for authentication#tls
configuring TLS settings#p_addr
,#p_port
,#p_user
,#p_pass
for proxy#json
make a JSON request with the appropriate HTTP headers (default tofalse
)#multipart
make a multipart request with the appropriate HTTP headers even if not sending a file (default tofalse
)#user_agent
set "User-Agent" HTTP header (default toCrest::USER_AGENT
)#max_redirects
maximum number of redirects (default to10
)#logging
enable logging (default tofalse
)#logger
set logger (default toCrest::CommonLogger
)#handle_errors
error handling (default totrue
)#close_connection
close the connection after request is completed (default totrue
)#http_client
instance ofHTTP::Client
#read_timeout
read timeout (default tonil
)#write_timeout
write timeout (default tonil
)#connect_timeout
connect timeout (default tonil
)
Defined in:
crest/request.crConstructors
- .new(method : Symbol, url : String, form = {} of String => String, *, headers = {} of String => String, cookies = {} of String => String, params = {} of String => String, max_redirects : Int32 = 10, **options, &)
-
.new(method : Symbol, url : String, form = {} of String => String, **args)
When block is not given.
Class Method Summary
-
.delete(url : String, form = {} of String => String, **args, &block : Crest::Response -> ) : Nil
Execute a DELETE request and and yields the
Crest::Response
to the block. -
.delete(url : String, form = {} of String => String, **args) : Crest::Response
Execute a DELETE request and returns a
Crest::Response
. - .execute(method, url, form = {} of String => String, **args) : Crest::Response
- .execute(method, url, form = {} of String => String, **args, &block : Crest::Response -> ) : Nil
-
.get(url : String, form = {} of String => String, **args, &block : Crest::Response -> ) : Nil
Execute a GET request and and yields the
Crest::Response
to the block. -
.get(url : String, form = {} of String => String, **args) : Crest::Response
Execute a GET request and returns a
Crest::Response
. -
.head(url : String, form = {} of String => String, **args, &block : Crest::Response -> ) : Nil
Execute a HEAD request and and yields the
Crest::Response
to the block. -
.head(url : String, form = {} of String => String, **args) : Crest::Response
Execute a HEAD request and returns a
Crest::Response
. -
.options(url : String, form = {} of String => String, **args, &block : Crest::Response -> ) : Nil
Execute a OPTIONS request and and yields the
Crest::Response
to the block. -
.options(url : String, form = {} of String => String, **args) : Crest::Response
Execute a OPTIONS request and returns a
Crest::Response
. -
.patch(url : String, form = {} of String => String, **args, &block : Crest::Response -> ) : Nil
Execute a PATCH request and and yields the
Crest::Response
to the block. -
.patch(url : String, form = {} of String => String, **args) : Crest::Response
Execute a PATCH request and returns a
Crest::Response
. -
.post(url : String, form = {} of String => String, **args, &block : Crest::Response -> ) : Nil
Execute a POST request and and yields the
Crest::Response
to the block. -
.post(url : String, form = {} of String => String, **args) : Crest::Response
Execute a POST request and returns a
Crest::Response
. -
.put(url : String, form = {} of String => String, **args, &block : Crest::Response -> ) : Nil
Execute a PUT request and and yields the
Crest::Response
to the block. -
.put(url : String, form = {} of String => String, **args) : Crest::Response
Execute a PUT request and returns a
Crest::Response
.
Instance Method Summary
- #auth : String
- #close(*args, **options)
- #close(*args, **options, &)
- #close_connection : Bool
- #closed?
- #connect_timeout : Float32 | Int32 | Time::Span | Nil
- #cookies : HTTP::Cookies
-
#execute : Crest::Response
Execute HTTP request
-
#execute(&block : Crest::Response -> ) : Nil
Execute streaming HTTP request
- #form_data : IO | Slice(UInt8) | String | Nil
- #handle_errors : Bool
- #headers : HTTP::Headers
- #host(*args, **options)
- #host(*args, **options, &)
- #http_client : HTTP::Client
- #http_request : HTTP::Request
- #json : Bool
- #logger : Crest::Logger
- #logging : Bool
- #max_redirects : Int32
- #method : String
- #multipart : Bool
- #p_addr : String?
- #p_pass : String?
- #p_port : Int32?
- #p_user : String?
- #password : String?
- #password=(password : Nil | String)
- #port(*args, **options)
- #port(*args, **options, &)
- #proxy : HTTP::Proxy::Client?
- #read_timeout : Float32 | Int32 | Time::Span | Nil
- #redirection_history : Array(Crest::Response)
- #redirection_history=(redirection_history : Array(Crest::Response))
- #tls : OpenSSL::SSL::Context::Client?
- #tls?(*args, **options)
- #tls?(*args, **options, &)
-
#to_curl
Convert
Request
object to cURL command - #url : String
- #user : String?
- #user=(user : Nil | String)
- #user_agent : String?
- #write_timeout : Float32 | Int32 | Time::Span | Nil
Constructor Detail
When block is not given.
Class Method Detail
Execute a DELETE request and and yields the Crest::Response
to the block.
Crest::Request.delete("http://httpbin.org/delete") do |resp|
while line = resp.body_io.gets
puts line
end
end
Execute a DELETE request and returns a Crest::Response
.
Crest::Request.delete("http://httpbin.org/delete")
Execute a GET request and and yields the Crest::Response
to the block.
Crest::Request.get("http://httpbin.org/get") do |resp|
while line = resp.body_io.gets
puts line
end
end
Execute a GET request and returns a Crest::Response
.
Crest::Request.get("http://httpbin.org/get")
Execute a HEAD request and and yields the Crest::Response
to the block.
Crest::Request.head("http://httpbin.org/head") do |resp|
while line = resp.body_io.gets
puts line
end
end
Execute a HEAD request and returns a Crest::Response
.
Crest::Request.head("http://httpbin.org/head")
Execute a OPTIONS request and and yields the Crest::Response
to the block.
Crest::Request.options("http://httpbin.org/options") do |resp|
while line = resp.body_io.gets
puts line
end
end
Execute a OPTIONS request and returns a Crest::Response
.
Crest::Request.options("http://httpbin.org/options")
Execute a PATCH request and and yields the Crest::Response
to the block.
Crest::Request.patch("http://httpbin.org/patch") do |resp|
while line = resp.body_io.gets
puts line
end
end
Execute a PATCH request and returns a Crest::Response
.
Crest::Request.patch("http://httpbin.org/patch")
Execute a POST request and and yields the Crest::Response
to the block.
Crest::Request.post("http://httpbin.org/post") do |resp|
while line = resp.body_io.gets
puts line
end
end
Execute a POST request and returns a Crest::Response
.
Crest::Request.post("http://httpbin.org/post")
Execute a PUT request and and yields the Crest::Response
to the block.
Crest::Request.put("http://httpbin.org/put") do |resp|
while line = resp.body_io.gets
puts line
end
end
Execute a PUT request and returns a Crest::Response
.
Crest::Request.put("http://httpbin.org/put")