class
Amber::Router::Router
- Amber::Router::Router
- Reference
- Object
Overview
This is the main application handler all routers should finally hit this handler.
Defined in:
amber/router/router.crConstant Summary
-
PATH_EXT_REGEX =
Controller::Helpers::Responders::Content::TYPE_EXT_REGEX
Constructors
Instance Method Summary
- #add(route : Route)
- #add_socket_route(route, handler : WebSockets::Server::Handler)
-
#all_routes : Array(RouteInfo)
Returns all registered routes as RouteInfo structs for introspection.
- #draw(valve : Symbol, namespace : String, &)
-
#draw(valve : Symbol, &)
This registers all the routes for the application
- #get_socket_handler(request) : WebSockets::Server::Handler
-
#match(http_verb, resource, request : HTTP::Request | Nil = nil) : RoutedResult(Route)
Matches a request path to a route.
- #match_by_controller_action(controller, action)
-
#match_by_name(name : Symbol) : Route | Nil
Looks up a named route by its symbol name.
- #match_by_request(request)
- #route_defined?(request)
-
#route_table : String
Returns a formatted route table string suitable for display.
-
#route_table_for(routes : Array(RouteInfo)) : String
Returns a formatted route table string for a given list of routes.
- #routes : Amber::Router::RouteSet(Amber::Route)
- #routes=(routes : Amber::Router::RouteSet(Amber::Route))
- #routes_hash : Hash(String, Amber::Route)
- #routes_hash=(routes_hash : Hash(String, Amber::Route))
- #scope : Amber::Router::Scope
- #scope=(scope : Amber::Router::Scope)
- #socket_route_defined?(request)
- #socket_routes : Array({path: String, handler: Amber::WebSockets::Server::Handler})
- #socket_routes=(socket_routes : Array(NamedTuple(path: String, handler: Amber::WebSockets::Server::Handler)))
Constructor Detail
Instance Method Detail
Returns all registered routes as RouteInfo structs for introspection.
Matches a request path to a route. Within one lookup, routes compete in
the order they were drawn. A path that ends in a known response
extension may take two lookups, and the first that qualifies wins, so a
later get "/overview.md" answers /overview.md ahead of an earlier
get "/overview".
A path ending in a known response extension (.json, .md, ...) is
matched in this order:
- the full path, when the route it reaches spells the extension as
the fixed end of its own path (
get "/overview.md",get "/overview(.md)") and that route's request constraint, if any, acceptsrequest; - the path without the extension (
/users/1.jsonmatches/users/:id, and the controller responds in that format); - the full path as written.
Step 1 runs only when some drawn route spells a known extension, so an
app without one matches exactly as before. A declared route whose
request constraint rejected request in step 1 is not offered again,
neither in step 3 nor in step 2 through another expansion of the same
route (get "/notes(.md)" also matches /notes). A different route
that matches the path without the extension still answers; when none
does, the path is not found.
Looks up a named route by its symbol name.
Returns a formatted route table string suitable for display.
Returns a formatted route table string for a given list of routes.