class Yeager::App
- Yeager::App
- Reference
- Object
Overview
Yeager::App
uses Yeager::Router
to handle HTTP requests
on a given (or created) HTTP::Server instance
App mimics the Express.js but not feature complete which only provides basic functionality with sugar helpers
It holds provided routes and handlers in separate hashes with
requested method (defined in HTTP_METHODS
)
It can create an HTTP::Server and attach the created
Yeager::HTTPHandler
with #listen
method but also the #handler
can be used on an existing HTTP::Server
Simple example would be;
app = Yeager::App.new
app.get "/" do |req, res|
res.send "Hello world!"
end
app.listen
which will create a HTTP::Server and start listening on port 3000
defined in DEFAULT_PORT
and will response with Hello world!
for
requests coming to /
with status_code 200
Router part supports the same feature set of Yeager::Router
also extends
req
and res
to provide similar functionalities of Express.js
app = Yeager::App.new
app.get "/json" do |req, res|
res.json({"foo" => "bar"})
end
app.get "/:name" do |req, res|
res.send "Hello #{req.params["name"]}"
end
app.listen
/test
rendersHello test
/json
renders{"foo": "bar"}
with content type ofjson
Defined in:
yeager/app.crConstructors
Instance Method Summary
- #delete(path : String, &cb : Handler)
- #get(path : String, &cb : Handler)
- #handler : Yeager::HTTPHandler
- #head(path : String, &cb : Handler)
- #listen(port = DEFAULT_PORT, host = DEFAULT_HOST)
- #listen(port = DEFAULT_PORT, host = DEFAULT_HOST, &cb : -> _)
- #patch(path : String, &cb : Handler)
- #post(path : String, &cb : Handler)
- #put(path : String, &cb : Handler)
- #routers : Hash(String, Yeager::Router)