class Yeager::App

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

Defined in:

yeager/app.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

[View source]

Instance Method Detail

def delete(path : String, &cb : Handler) #

[View source]
def get(path : String, &cb : Handler) #

[View source]
def handler : Yeager::HTTPHandler #

[View source]
def head(path : String, &cb : Handler) #

[View source]
def listen(port = DEFAULT_PORT, host = DEFAULT_HOST) #

[View source]
def listen(port = DEFAULT_PORT, host = DEFAULT_HOST, &cb : -> _) #

[View source]
def patch(path : String, &cb : Handler) #

[View source]
def post(path : String, &cb : Handler) #

[View source]
def put(path : String, &cb : Handler) #

[View source]
def routers : Hash(String, Yeager::Router) #

[View source]