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_EXTENSIONS =
Controller::Helpers::Responders::Content::TYPE.keys.map do |key| ".#{key}" end -
The response extensions a path can end in, dot included (
".json"), one perContent::TYPEkey. No key is a dotted suffix of another, so at most one of them ends any path.
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.
-
#constrain_socket_route(handler : WebSockets::Server::Handler, constraint : Constraint) : Nil
Holds the socket route served by handler to constraint, the
constraintblock itswebsocketline sits in. - #draw(valve : Symbol, namespace : String, &)
-
#draw(valve : Symbol, &)
This registers all the routes for the application
-
#get_socket_handler(request) : WebSockets::Server::Handler
Returns the handler of the first socket route whose path is request's and whose constraint, if it was declared in a
constraintblock, request meets. -
#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_constraint(handler : WebSockets::Server::Handler) : Constraint | Nil
Returns the constraint the socket route served by handler was declared under, or
nilwhen it was declared outside any. - #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.
Holds the socket route served by handler to constraint, the
constraint block its websocket line sits in.
Returns the handler of the first socket route whose path is
request's and whose constraint, if it was declared in a
constraint block, request meets. Raises
Exceptions::RouteNotFound when there is none.
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.
Returns the constraint the socket route served by handler was
declared under, or nil when it was declared outside any.