Crest::Request
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:
methodurl
Optional parameters:
headersa hash containing the request headerscookiesa hash containing the request cookiesforma hash containing form data (or a raw string)paramsa 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_encoderparams encoder (default toCrest::FlatParamsEncoder)authaccess authentication methodbasicordigest(default tobasic)userandpasswordfor authenticationtlsconfiguring TLS settingsp_addr,p_port,p_user,p_passfor proxyjsonmake a JSON request with the appropriate HTTP headers (default tofalse)multipartmake a multipart request with the appropriate HTTP headers even if not sending a file (default tofalse)stream_multipartstream multipart request body to reduce memory usage (default tofalse)user_agentset "User-Agent" HTTP header (default toCrest::USER_AGENT)max_redirectsmaximum number of redirects (default to10)loggingenable logging (default tofalse)loggerset logger (default toCrest::CommonLogger)handle_errorserror handling (default totrue)close_connectionclose the connection after request is completed (default totrue)http_clientinstance ofHTTP::Clientread_timeoutread timeout (default tonil)write_timeoutwrite timeout (default tonil)connect_timeoutconnect timeout (default tonil)
Constructors
Class methods
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")