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:
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)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)
Defined in:
lib/crest/src/crest/request.crextensions/request.cr
Constructors
Constructor Detail
def self.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, &)
#