class Halite::Client

Overview

Clients make requests and receive responses

Support all Chainable methods.

Simple setup

client = Halite::Client.new(headers: {
  "private-token" => "bdf39d82661358f80b31b67e6f89fee4"
})

client.auth(private_token: "bdf39d82661358f80b31b67e6f89fee4").
      .get("http://httpbin.org/get", params: {
        name: "icyleaf"
      })

Setup with block

client = Halite::Client.new do
  basic_auth "name", "foo"
  headers content_type: "application/jsong"
  read_timeout 3.minutes
  logging true
end

Included Modules

Defined in:

halite/client.cr

Constructors

Instance Method Summary

Instance methods inherited from module Halite::Chainable

accept(value : String) : Halite::Client accept, auth(value : String) : Halite::Client auth, basic_auth(user : String, pass : String) : Halite::Client basic_auth, cookies(cookies : Hash(String, _) | NamedTuple) : Halite::Client
cookies(cookies : HTTP::Cookies) : Halite::Client
cookies(**kargs) : Halite::Client
cookies
, delete(uri : String, *, headers : Hash(String, _) | NamedTuple | Nil = nil, params : Hash(String, _) | NamedTuple | Nil = nil, form : Hash(String, _) | NamedTuple | Nil = nil, json : Hash(String, _) | NamedTuple | Nil = nil, raw : String | Nil = nil, tls : OpenSSL::SSL::Context::Client | Nil = nil) : Halite::Response
delete(uri : String, *, headers : Hash(String, _) | NamedTuple | Nil = nil, params : Hash(String, _) | NamedTuple | Nil = nil, form : Hash(String, _) | NamedTuple | Nil = nil, json : Hash(String, _) | NamedTuple | Nil = nil, raw : String | Nil = nil, tls : OpenSSL::SSL::Context::Client | Nil = nil, &block : Halite::Response -> )
delete
, endpoint(endpoint : String | URI) : Halite::Client endpoint, follow(hops : Int32, strict = Halite::Options::Follow::STRICT) : Halite::Client
follow(strict = Halite::Options::Follow::STRICT) : Halite::Client
follow
, get(uri : String, *, headers : Hash(String, _) | NamedTuple | Nil = nil, params : Hash(String, _) | NamedTuple | Nil = nil, raw : String | Nil = nil, tls : OpenSSL::SSL::Context::Client | Nil = nil) : Halite::Response
get(uri : String, *, headers : Hash(String, _) | NamedTuple | Nil = nil, params : Hash(String, _) | NamedTuple | Nil = nil, raw : String | Nil = nil, tls : OpenSSL::SSL::Context::Client | Nil = nil, &block : Halite::Response -> )
get
, head(uri : String, *, headers : Hash(String, _) | NamedTuple | Nil = nil, params : Hash(String, _) | NamedTuple | Nil = nil, raw : String | Nil = nil, tls : OpenSSL::SSL::Context::Client | Nil = nil) : Halite::Response
head(uri : String, *, headers : Hash(String, _) | NamedTuple | Nil = nil, params : Hash(String, _) | NamedTuple | Nil = nil, raw : String | Nil = nil, tls : OpenSSL::SSL::Context::Client | Nil = nil, &block : Halite::Response -> )
head
, headers(headers : Hash(String, _) | NamedTuple) : Halite::Client
headers(**kargs) : Halite::Client
headers
, logging(enable : Bool = true)
logging(logging : Halite::Logging::Abstract = Halite::Logging::Common.new)
logging(format : String = "common", *, for : String = "halite", skip_request_body = false, skip_response_body = false, skip_benchmark = false, colorize = true)
logging
, options(uri : String, *, headers : Hash(String, _) | NamedTuple | Nil = nil, params : Hash(String, _) | NamedTuple | Nil = nil, form : Hash(String, _) | NamedTuple | Nil = nil, json : Hash(String, _) | NamedTuple | Nil = nil, raw : String | Nil = nil, tls : OpenSSL::SSL::Context::Client | Nil = nil) : Halite::Response
options(uri : String, *, headers : Hash(String, _) | NamedTuple | Nil = nil, params : Hash(String, _) | NamedTuple | Nil = nil, form : Hash(String, _) | NamedTuple | Nil = nil, json : Hash(String, _) | NamedTuple | Nil = nil, raw : String | Nil = nil, tls : OpenSSL::SSL::Context::Client | Nil = nil, &block : Halite::Response -> )
options
, patch(uri : String, *, headers : Hash(String, _) | NamedTuple | Nil = nil, params : Hash(String, _) | NamedTuple | Nil = nil, form : Hash(String, _) | NamedTuple | Nil = nil, json : Hash(String, _) | NamedTuple | Nil = nil, raw : String | Nil = nil, tls : OpenSSL::SSL::Context::Client | Nil = nil) : Halite::Response
patch(uri : String, *, headers : Hash(String, _) | NamedTuple | Nil = nil, params : Hash(String, _) | NamedTuple | Nil = nil, form : Hash(String, _) | NamedTuple | Nil = nil, json : Hash(String, _) | NamedTuple | Nil = nil, raw : String | Nil = nil, tls : OpenSSL::SSL::Context::Client | Nil = nil, &block : Halite::Response -> )
patch
, post(uri : String, *, headers : Hash(String, _) | NamedTuple | Nil = nil, params : Hash(String, _) | NamedTuple | Nil = nil, form : Hash(String, _) | NamedTuple | Nil = nil, json : Hash(String, _) | NamedTuple | Nil = nil, raw : String | Nil = nil, tls : OpenSSL::SSL::Context::Client | Nil = nil) : Halite::Response
post(uri : String, *, headers : Hash(String, _) | NamedTuple | Nil = nil, params : Hash(String, _) | NamedTuple | Nil = nil, form : Hash(String, _) | NamedTuple | Nil = nil, json : Hash(String, _) | NamedTuple | Nil = nil, raw : String | Nil = nil, tls : OpenSSL::SSL::Context::Client | Nil = nil, &block : Halite::Response -> )
post
, put(uri : String, *, headers : Hash(String, _) | NamedTuple | Nil = nil, params : Hash(String, _) | NamedTuple | Nil = nil, form : Hash(String, _) | NamedTuple | Nil = nil, json : Hash(String, _) | NamedTuple | Nil = nil, raw : String | Nil = nil, tls : OpenSSL::SSL::Context::Client | Nil = nil) : Halite::Response
put(uri : String, *, headers : Hash(String, _) | NamedTuple | Nil = nil, params : Hash(String, _) | NamedTuple | Nil = nil, form : Hash(String, _) | NamedTuple | Nil = nil, json : Hash(String, _) | NamedTuple | Nil = nil, raw : String | Nil = nil, tls : OpenSSL::SSL::Context::Client | Nil = nil, &block : Halite::Response -> )
put
, request(verb : String, uri : String, options : Halite::Options | Nil = nil) : Halite::Response
request(verb : String, uri : String, *, headers : Hash(String, _) | NamedTuple | Nil = nil, params : Hash(String, _) | NamedTuple | Nil = nil, form : Hash(String, _) | NamedTuple | Nil = nil, json : Hash(String, _) | NamedTuple | Nil = nil, raw : String | Nil = nil, tls : OpenSSL::SSL::Context::Client | Nil = nil) : Halite::Response
request(verb : String, uri : String, options : Halite::Options | Nil = nil, &block : Halite::Response -> )
request(verb : String, uri : String, *, headers : Hash(String, _) | NamedTuple | Nil = nil, params : Hash(String, _) | NamedTuple | Nil = nil, form : Hash(String, _) | NamedTuple | Nil = nil, json : Hash(String, _) | NamedTuple | Nil = nil, raw : String | Nil = nil, tls : OpenSSL::SSL::Context::Client | Nil = nil, &block : Halite::Response -> )
request
, timeout(connect : Int32 | Float64 | Time::Span | Nil = nil, read : Int32 | Float64 | Time::Span | Nil = nil, write : Int32 | Float64 | Time::Span | Nil = nil) timeout, use(*features)
use(feature : String, **opts)
use
, user_agent(value : String) : Halite::Client user_agent

Constructor Detail

def self.new(options : Halite::Options = Halite::Options.new) #

Instance a new client

options = Halite::Options.new(headers: {
  "private-token" => "bdf39d82661358f80b31b67e6f89fee4",
})

client = Halite::Client.new(options)

[View source]
def self.new(*, endpoint : String | URI | Nil = nil, headers : Hash(String, _) | NamedTuple | Nil = nil, cookies : Hash(String, _) | NamedTuple | Nil = nil, params : Hash(String, _) | NamedTuple | Nil = nil, form : Hash(String, _) | NamedTuple | Nil = nil, json : Hash(String, _) | NamedTuple | Nil = nil, raw : String | Nil = nil, timeout = Timeout.new, follow = Follow.new, tls : OpenSSL::SSL::Context::Client | Nil = nil) #

Instance a new client

Halite::Client.new(headers: {"private-token" => "bdf39d82661358f80b31b67e6f89fee4"})

[View source]
def self.new(&) #

Instance a new client with block

client = Halite::Client.new do
  basic_auth "name", "foo"
  logging true
end

[View source]

Instance Method Detail

def options : Halite::Options #

[View source]
def options=(options : Halite::Options) #

[View source]
def request(verb : String, uri : String, options : Halite::Options | Nil = nil) : Halite::Response #

Make an HTTP request


[View source]
def request(verb : String, uri : String, options : Halite::Options | Nil = nil, &block : Halite::Response -> ) #

Make an HTTP request


[View source]