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)

When block is not given.

Source

Class methods

delete(url : String, form = {} of String => String, **args, &block : Crest::Response -> ) : Nil

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
Source
delete(url : String, form = {} of String => String, **args) : Crest::Response

Execute a DELETE request and returns a Crest::Response.

Crest::Request.delete("http://httpbin.org/delete")
Source
execute(method, url, form = {} of String => String, **args) : Crest::Response
Source
execute(method, url, form = {} of String => String, **args, &block : Crest::Response -> ) : Nil
Source
get(url : String, form = {} of String => String, **args, &block : Crest::Response -> ) : Nil

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
Source
get(url : String, form = {} of String => String, **args) : Crest::Response

Execute a GET request and returns a Crest::Response.

Crest::Request.get("http://httpbin.org/get")
Source
head(url : String, form = {} of String => String, **args, &block : Crest::Response -> ) : Nil

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
Source
head(url : String, form = {} of String => String, **args) : Crest::Response

Execute a HEAD request and returns a Crest::Response.

Crest::Request.head("http://httpbin.org/head")
Source
options(url : String, form = {} of String => String, **args, &block : Crest::Response -> ) : Nil

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
Source
options(url : String, form = {} of String => String, **args) : Crest::Response

Execute a OPTIONS request and returns a Crest::Response.

Crest::Request.options("http://httpbin.org/options")
Source
patch(url : String, form = {} of String => String, **args, &block : Crest::Response -> ) : Nil

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
Source
patch(url : String, form = {} of String => String, **args) : Crest::Response

Execute a PATCH request and returns a Crest::Response.

Crest::Request.patch("http://httpbin.org/patch")
Source
post(url : String, form = {} of String => String, **args, &block : Crest::Response -> ) : Nil

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
Source
post(url : String, form = {} of String => String, **args) : Crest::Response

Execute a POST request and returns a Crest::Response.

Crest::Request.post("http://httpbin.org/post")
Source
put(url : String, form = {} of String => String, **args, &block : Crest::Response -> ) : Nil

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
Source
put(url : String, form = {} of String => String, **args) : Crest::Response

Execute a PUT request and returns a Crest::Response.

Crest::Request.put("http://httpbin.org/put")
Source

Instance methods

auth
Source
close(*args, **options)
Source
close(*args, **options, &)
Source
close_connection
Source
closed?
Source
connect_timeout
Source
cookies
Source
execute

Execute HTTP request

Source
execute

Execute streaming HTTP request

Source
form_data
Source
handle_errors
Source
headers
Source
host(*args, **options)
Source
host(*args, **options, &)
Source
http_client
Source
http_request
Source
json
Source
logger
Source
logging
Source
max_redirects
Source
method
Source
multipart
Source
p_addr
Source
p_pass
Source
p_port
Source
p_user
Source
params_encoder
Source
password
Source
password=(password : Nil | String)
Source
port(*args, **options)
Source
port(*args, **options, &)
Source
proxy
Source
read_timeout
Source
redirection_history
Source
redirection_history=(redirection_history : Array(Crest::Response))
Source
stream_multipart
Source
tls?(*args, **options)
Source
tls?(*args, **options, &)
Source
to_curl

Convert Request object to cURL command

Source
user
Source
user=(user : Nil | String)
Source
user_agent
Source
write_timeout
Source