module Crest

Overview

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

Defined in:

crest.cr
crest/curlify.cr
crest/exceptions.cr
crest/form.cr
crest/forms/data_form.cr
crest/forms/json_form.cr
crest/forms/stream_data_form.cr
crest/forms/urlencoded_form.cr
crest/logger.cr
crest/loggers/common_logger.cr
crest/params_decoder.cr
crest/params_encoder.cr
crest/params_encoders/enumerated_flat_params_encoder.cr
crest/params_encoders/flat_params_encoder.cr
crest/params_encoders/nested_params_encoder.cr
crest/params_encoders/zero_enumerated_flat_params_encoder.cr
crest/redirector.cr
crest/request.cr
crest/resource.cr
crest/response.cr

Constant Summary

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 /home/runner/work/crest/crest/src`).chomp.stringify }}

Class Method Summary

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.delete("http://httpbin.org/delete") do |response|
  while line = response.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.delete("http://httpbin.org/delete")

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

[View source]