class

Crest::Request

Inherits Reference < Object

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 headers
  • cookies a hash containing the request cookies
  • form 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 to Crest::FlatParamsEncoder)
  • auth access authentication method basic or digest (default to basic)
  • 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 to false)
  • multipart make a multipart request with the appropriate HTTP headers even if not sending a file (default to false)
  • stream_multipart stream multipart request body to reduce memory usage (default to false)
  • user_agent set "User-Agent" HTTP header (default to Crest::USER_AGENT)
  • max_redirects maximum number of redirects (default to 10)
  • logging enable logging (default to false)
  • logger set logger (default to Crest::CommonLogger)
  • handle_errors error handling (default to true)
  • close_connection close the connection after request is completed (default to true)
  • http_client instance of HTTP::Client
  • read_timeout read timeout (default to nil)
  • write_timeout write timeout (default to nil)
  • connect_timeout connect timeout (default to nil)

Constructors

new(method : Symbol, url : String, form = {} of String => String, **args)

Keep this signature aligned with Crest::Request#initialize. If Crest changes the signature, this local extension needs to follow.

Source