module

Crest

This module's static methods are the entry point for using the Crest client.

Supported HTTP methods: get, put, post, patch delete, options, head

Examples:

Crest.get(
  "http://httpbin.org/get",
  headers: {"Content-Type" => "image/jpg"},
  params: {"lang" => "en"}
)

Crest.post(
  "http://httpbin.org/post",
  headers: {"Access-Token" => ["secret1", "secret2"]},
  form: {"fizz" => "buz"},
  logging: true,
)

Crest.get("http://httpbin.org/stream/5") do |response|
  while line = response.body_io.gets
    puts line
  end
end

Constants

EXCEPTIONS_MAP = {} of Int32 => Crest::RequestFailed.class
HTTP_METHODS = ["get", "delete", "post", "put", "patch", "options", "head"] of ::String
STATUSES = ({} of Int32 => String).tap do |statuses| HTTP::Status.each do |status| if description = status.description statuses[status.code] = description end end end

Hash of HTTP status code => standard-library description.

USER_AGENT = "Crest/#{Crest::VERSION} (Crystal/#{Crystal::VERSION})"
VERSION = {{ (`shards version /tmp/tmp.CAiIhF/src/src`).chomp.stringify }}

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.delete("http://httpbin.org/delete") do |response|
  while line = response.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.delete("http://httpbin.org/delete")
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.get("http://httpbin.org/get") do |response|
  while line = response.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.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.head("http://httpbin.org/head") do |response|
  while line = response.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.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.options("http://httpbin.org/options") do |response|
  while line = response.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.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.patch("http://httpbin.org/patch") do |response|
  while line = response.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.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.post("http://httpbin.org/post") do |response|
  while line = response.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.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.put("http://httpbin.org/put") do |response|
  while line = response.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.put("http://httpbin.org/put")
Source

Nested types