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(method: :post, url: "http://httpbin.org/post", form: {:age => 27}, params: {:name => "Kurt"})
request.execute
Crest::Request.execute(method: :post, url: "http://httpbin.org/post", form: {:age => 27}.to_json)
Crest::Request.post(url: http://httpbin.org/post", form: {:age => 27}.to_json)
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 params (or a raw string)params
a hash that represent query-string separated from the preceding part by a question mark (?) a sequence of attribute–value pairs separated by a delimiter (&).#auth
access authentication methodbasic
ordigest
(default tobasic
)#user
and#password
for authenticationtls
configuring TLS settings#p_addr
,#p_port
,#p_user
,#p_pass
for proxy#max_redirects
maximum number of redirections (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
Defined in:
crest/request.crConstructors
- .new(method : Symbol, url : String, *, headers = {} of String => String, cookies = {} of String => String, form = {} of String => String, params = {} of String => String, max_redirects : Int32 = 10, **options, &)
-
.new(method : Symbol, url : String, **args)
When block is not given.
Class Method Summary
-
.delete(url : String, **args, &block : Crest::Response -> ) : Nil
Execute a DELETE request and and yields the
Crest::Response
to the block. -
.delete(url : String, **args) : Crest::Response
Execute a DELETE request and returns a
Crest::Response
. - .execute(method, url, **args) : Crest::Response
- .execute(method, url, **args, &block : Crest::Response -> ) : Nil
-
.get(url : String, **args, &block : Crest::Response -> ) : Nil
Execute a GET request and and yields the
Crest::Response
to the block. -
.get(url : String, **args) : Crest::Response
Execute a GET request and returns a
Crest::Response
. -
.head(url : String, **args, &block : Crest::Response -> ) : Nil
Execute a HEAD request and and yields the
Crest::Response
to the block. -
.head(url : String, **args) : Crest::Response
Execute a HEAD request and returns a
Crest::Response
. -
.options(url : String, **args, &block : Crest::Response -> ) : Nil
Execute a OPTIONS request and and yields the
Crest::Response
to the block. -
.options(url : String, **args) : Crest::Response
Execute a OPTIONS request and returns a
Crest::Response
. -
.patch(url : String, **args, &block : Crest::Response -> ) : Nil
Execute a PATCH request and and yields the
Crest::Response
to the block. -
.patch(url : String, **args) : Crest::Response
Execute a PATCH request and returns a
Crest::Response
. -
.post(url : String, **args, &block : Crest::Response -> ) : Nil
Execute a POST request and and yields the
Crest::Response
to the block. -
.post(url : String, **args) : Crest::Response
Execute a POST request and returns a
Crest::Response
. -
.put(url : String, **args, &block : Crest::Response -> ) : Nil
Execute a PUT request and and yields the
Crest::Response
to the block. -
.put(url : 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
- #cookies : HTTP::Cookies
-
#execute : Crest::Response
Execute HTTP request
-
#execute(&block : Crest::Response -> ) : Nil
Execute streaming HTTP request
- #form_data : String?
- #handle_errors : Bool
- #headers : HTTP::Headers
- #host(*args, **options)
- #host(*args, **options, &)
- #http_client : HTTP::Client
- #http_request : HTTP::Request
- #logger : Crest::Logger
- #logging : Bool
- #max_redirects : Int32
- #method : String
- #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?
- #redirection_history : Array(Crest::Response)
- #redirection_history=(redirection_history : Array(Crest::Response))
- #tls?(*args, **options)
- #tls?(*args, **options, &)
-
#to_curl
Convert
Request
object to cURL command - #url : String
- #user : String?
- #user=(user : Nil | String)
Constructor Detail
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")