class Crest::Request

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:

Optional parameters:

Defined in:

crest/request.cr

Constructors

Class Method Summary

Instance Method Summary

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 = 10, **options, &) #

[View source]
def self.new(method : Symbol, url : String, form = {} of String => String, **args) #

When block is not given.


[View source]

Class Method Detail

def self.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

[View source]
def self.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")

[View source]
def self.execute(method, url, form = {} of String => String, **args) : Crest::Response #

[View source]
def self.execute(method, url, form = {} of String => String, **args, &block : Crest::Response -> ) : Nil #

[View source]
def self.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

[View source]
def self.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")

[View source]
def self.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

[View source]
def self.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")

[View source]
def self.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

[View source]
def self.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")

[View source]
def self.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

[View source]
def self.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")

[View source]
def self.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

[View source]
def self.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")

[View source]
def self.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

[View source]
def self.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")

[View source]

Instance Method Detail

def auth : String #

[View source]
def close(*args, **options) #

[View source]
def close(*args, **options, &) #

[View source]
def close_connection : Bool #

[View source]
def connect_timeout : Float32 | Int32 | Time::Span | Nil #

[View source]
def cookies : HTTP::Cookies #

[View source]
def execute : Crest::Response #

Execute HTTP request


[View source]
def execute(&block : Crest::Response -> ) : Nil #

Execute streaming HTTP request


[View source]
def form_data : String? #

[View source]
def handle_errors : Bool #

[View source]
def headers : HTTP::Headers #

[View source]
def host(*args, **options) #

[View source]
def host(*args, **options, &) #

[View source]
def http_client : HTTP::Client #

[View source]
def http_request : HTTP::Request #

[View source]
def json : Bool #

[View source]
def logger : Crest::Logger #

[View source]
def logging : Bool #

[View source]
def max_redirects : Int32 #

[View source]
def method : String #

[View source]
def p_addr : String? #

[View source]
def p_pass : String? #

[View source]
def p_port : Int32? #

[View source]
def p_user : String? #

[View source]
def password : String? #

[View source]
def password=(password) #

[View source]
def port(*args, **options) #

[View source]
def port(*args, **options, &) #

[View source]
def proxy : HTTP::Proxy::Client? #

[View source]
def read_timeout : Float32 | Int32 | Time::Span | Nil #

[View source]
def redirection_history : Array(Crest::Response) #

[View source]
def redirection_history=(redirection_history) #

[View source]
def tls : OpenSSL::SSL::Context::Client? #

[View source]
def tls?(*args, **options) #

[View source]
def tls?(*args, **options, &) #

[View source]
def to_curl #

Convert Request object to cURL command


[View source]
def url : String #

[View source]
def user : String? #

[View source]
def user=(user) #

[View source]
def user_agent : String? #

[View source]
def write_timeout : Float32 | Int32 | Time::Span | Nil #

[View source]