abstract class Lucky::BaseHTTPClient
- Lucky::BaseHTTPClient
- Reference
- Object
Overview
A client for making HTTP requests
Makes it easy to pass params, use Lucky route helpers, and chain header methods.
Defined in:
lucky/base_http_client.crConstructors
Class Method Summary
- .app(app : Lucky::BaseAppServer)
- .delete(*args, **named_args)
- .exec(*args, **named_args)
- .get(*args, **named_args)
- .head(*args, **named_args)
- .options(*args, **named_args)
- .patch(*args, **named_args)
- .post(*args, **named_args)
- .put(*args, **named_args)
Instance Method Summary
- #delete(path : String, params : NamedTuple) : HTTP::Client::Response
- #delete(path : String, **params) : HTTP::Client::Response
-
#exec(route_helper : Lucky::RouteHelper, params : NamedTuple) : HTTP::Client::Response
See docs for
#exec
-
#exec(action : Lucky::Action.class, **params) : HTTP::Client::Response
Sends a request with the path and method from a Lucky::Action
-
#exec(route_helper : Lucky::RouteHelper, **params) : HTTP::Client::Response
See docs for
#exec
- #exec_raw(action : Lucky::Action.class, body : String) : HTTP::Client::Response
-
#exec_raw(route_helper : Lucky::RouteHelper, body : String) : HTTP::Client::Response
See docs for
#exec_raw
- #get(path : String, params : NamedTuple) : HTTP::Client::Response
- #get(path : String, **params) : HTTP::Client::Response
- #head(path : String, params : NamedTuple) : HTTP::Client::Response
- #head(path : String, **params) : HTTP::Client::Response
-
#headers(**header_values) : self
The header call is chainable and returns the client:
- #options(path : String, params : NamedTuple) : HTTP::Client::Response
- #options(path : String, **params) : HTTP::Client::Response
- #patch(path : String, params : NamedTuple) : HTTP::Client::Response
- #patch(path : String, **params) : HTTP::Client::Response
- #post(path : String, params : NamedTuple) : HTTP::Client::Response
- #post(path : String, **params) : HTTP::Client::Response
- #put(path : String, params : NamedTuple) : HTTP::Client::Response
- #put(path : String, **params) : HTTP::Client::Response
Constructor Detail
Class Method Detail
Instance Method Detail
def exec(route_helper : Lucky::RouteHelper, params : NamedTuple) : HTTP::Client::Response
#
See docs for #exec
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: "[email protected]"}
# Actions that require path params work like normal
AppClient.new.exec Users::Show.with(user.id)
#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.
See docs for #exec_raw
def headers(**header_values) : self
#
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")