class

Azu::Router

Inherits Reference < Object

Defines an Azu Router

The router provides a set of methods for mapping routes that dispatch to specific endpoints or handers. For example

MyAppWeb.router do
  root :web, ExampleApp::HelloWorld
  ws "/hi", ExampleApp::ExampleChannel

  routes :web, "/test" do
    get "/hello/", ExampleApp::HelloWorld
    get "/hello/:name", ExampleApp::HtmlEndpoint
    get "/hello/json", ExampleApp::JsonEndpoint
  end
end

You can use most common HTTP verbs: GET, POST, PUT, PATCH, DELETE, TRACE and OPTIONS.

endpoint = ->(env) { [200, {}, ['Hello from Hanami!']] }

get     '/hello', to: endpoint
post    '/hello', to: endpoint
put     '/hello', to: endpoint
patch   '/hello', to: endpoint
delete  '/hello', to: endpoint
trace   '/hello', to: endpoint
options '/hello', to: endpoint

Constants

METHOD_OVERRIDE = "_method"
RESOURCES = ["connect", "delete", "get", "head", "options", "patch", "post", "put", "trace"] of ::String

Constructors

Instance methods

add(path : Path, endpoint : HTTP::Handler, method : Azu::Method = Azu::Method::Get)

Registers a route for a given path

add path: '/proc', endpoint: ->(env) { [200, {}, ['Hello from Hanami!']] }, method: Azu::Method::Get
add path: '/endpoint',   endpoint: Handler.new, method: Azu::Method::Get
Source
clear_path_cache

Clear path cache (useful for testing or memory management)

Source
connect(path : Router::Path, handler : HTTP::Handler)
Source
delete(path : Router::Path, handler : HTTP::Handler)
Source
get(path : Router::Path, handler : HTTP::Handler)
Source
head(path : Router::Path, handler : HTTP::Handler)
Source
options(path : Router::Path, handler : HTTP::Handler)
Source
patch(path : Router::Path, handler : HTTP::Handler)
Source
path_cache
Source
post(path : Router::Path, handler : HTTP::Handler)
Source
process(context : HTTP::Server::Context)
Source
put(path : Router::Path, handler : HTTP::Handler)
Source
radix
Source
root(endpoint : HTTP::Handler)

Registers the main route of the application

root :web, ExampleApp::HelloWorld
Source
route_info

Get route information for development tools Build array of routes from the routes registry

Source
routes(scope : String = "", &)

Adds scoped routes

Source
trace(path : Router::Path, handler : HTTP::Handler)
Source
ws(path : String, channel : Channel.class)

Registers a websocket route

ws "/hi", ExampleApp::ExampleChannel
Source

Nested types