Lucky::BaseHTTPClient
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)
SourceClass methods
app(app : Lucky::BaseAppServer)
Sourcedelete(*args, **named_args)
Sourceexec(*args, **named_args)
Sourceget(*args, **named_args)
Sourcehead(*args, **named_args)
Sourceoptions(*args, **named_args)
Sourcepatch(*args, **named_args)
Sourcepost(*args, **named_args)
Sourceput(*args, **named_args)
SourceInstance methods
See docs for exec
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: "paul@example.com"}
# 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
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")