abstract class Bezel::Endpoint
An application's entry: the plugs every request goes through, in
order, the last of them usually the router. An endpoint is a class
whose plugs the application writes; Bezel.start serves it, and a
test calls it without a socket (MyApp::Endpoint.call(req)).
class Shop < Bezel::Endpoint
def self.plugs -> Array[Bezel::Plug]
[Bezel::Plug::RequestId.new,
Bezel::Plug::Parsers.new,
Bezel.plug { |conn| conn.text("hello #{conn.params.fetch("name", "you")}") }]
end
end
res = Shop.call(HTTP::Server::Request.get("/?name=Ann"))
res.status # => 200
res.body # => HTTP::Content::Text(text: "hello Ann")
A request that no plug answers is 404 Not Found. An exception a plug
raises is answered by Bezel::ErrorPage (an HTTP::Error with its
status, any other StandardError with 500), and a 500 is reported
to on_error first.
Class methods
def self.plugs -> Array[Bezel::Plug]
The plugs, in order. An endpoint overrides it; the plugs are made once, when its handler is.
def self.on_error(error: Exception, conn: Bezel::Conn) -> Void
Reports an exception answered with 500; conn is the connection
as the plug that raised received it (after the plugs before it: the
method Plug::MethodOverride set, the body's parameters). By default to standard error, with its
backtrace; override it to send errors elsewhere. An exception it
raises is written to standard error and goes no further.
def self.handler(app: Bezel::App = …) -> Bezel::Runner
The endpoint as an HTTP::Handler for app: what Bezel.start
gives the server.
def self.call(req: HTTP::Server::Request, app: Bezel::App = …) -> HTTP::Server::Response
The response to req, through a handler made for this call (app
by default a test application without a database).