class

Lucky::BaseHTTPClient

Inherits Reference < Object

A client for making HTTP requests

Makes it easy to pass params, use Lucky route helpers, and chain header methods.

Constructors

new(client : HTTP::Client = build_client)
Source

Class methods

delete(*args, **named_args)
Source
exec(*args, **named_args)
Source
get(*args, **named_args)
Source
head(*args, **named_args)
Source
options(*args, **named_args)
Source
patch(*args, **named_args)
Source
post(*args, **named_args)
Source
put(*args, **named_args)
Source

Instance methods

delete(path : String, **params) : HTTP::Client::Response
Source
exec(action : Lucky::Action.class, params : NamedTuple) : HTTP::Client::Response

See docs for exec

Source
exec(route_helper : Lucky::RouteHelper, params : NamedTuple) : HTTP::Client::Response

See docs for exec

Source
exec(action : Lucky::Action.class, **params) : HTTP::Client::Response

Sends a request with the path and method from a Lucky::Action

# Make a request without body params
AppClient.new.exec Users::Index

# Make a request with body params
AppClient.new.exec Users::Create, user: {email: "paul@example.com"}

# Actions that require path params work like normal
AppClient.new.exec Users::Show.with(user.id)
Source
exec(route_helper : Lucky::RouteHelper, **params) : HTTP::Client::Response

See docs for exec

Source

exec_raw works the same as exec, but allows you to pass in a raw string. This is used as an escape hatch as the string could be unsafe, or formatted in a custom format.

Source

See docs for exec_raw

Source
get(path : String, **params) : HTTP::Client::Response
Source
head(path : String, **params) : HTTP::Client::Response
Source
headers

The header call is chainable and returns the client:

# content_type will be normalized to `content-type`
AppClient.new
  .headers(content_type: "application/json")
  .headers(accept: "text/plain")
  .get("/some-path")

You can also set up headers in initialize or in instance methods:

class AppClient < Lucky::BaseHTTPClient
  def initialize
    headers(content_type: "application/json")
  end

  def accept_plain_text
    headers(accept: "text/plain")
  end
end

AppClient.new
  .accept_plain_text
  .get("/some-path")
Source
options(path : String, params : NamedTuple) : HTTP::Client::Response
Source
options(path : String, **params) : HTTP::Client::Response
Source
patch(path : String, **params) : HTTP::Client::Response
Source
post(path : String, params : NamedTuple) : HTTP::Client::Response
Source
post(path : String, **params) : HTTP::Client::Response
Source
put(path : String, **params) : HTTP::Client::Response
Source