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:
method
url
Optional parameters:
headers
a hash containing the request headerscookies
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
andpassword
for authenticationtls
configuring TLS settingsp_addr
,p_port
,p_user
,p_pass
for proxyjson
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:
lib/crest/src/crest/request.crext/crest.cr
Constructors
-
.new(method : Symbol, url : String, form = {} of String => String, **args)
When block is not given.
Constructor Detail
When block is not given.