livery_router (livery v0.1.0)
View SourceRadix-style path-segment router.
Routes are compiled into an immutable trie. Each segment of a pattern is one of:
- static, e.g.
usersin/users/new; - parameter, prefixed with
:, e.g.:idin/users/:id; - wildcard, prefixed with
*, e.g.*pathin/files/*path, matching all remaining segments joined back with/.
match/3 returns {ok, Handler, Bindings, Meta} on a
method-aware hit, {error, {method_not_allowed, Methods}} when
the path matches but no route is registered for the requested
method, or {error, not_found} otherwise.
Summary
Functions
Insert one route.
Build a router from a list of routes in one shot.
Look up a route by method and path.
Empty router with no routes.
Types
Functions
Insert one route.
Method may be '_' to match any HTTP method. Later additions with
the same Method+Pattern replace the previous entry.
-spec compile([{method(), pattern(), handler()} | {method(), pattern(), handler(), meta()}]) -> router().
Build a router from a list of routes in one shot.
-spec match(method(), binary(), router()) -> {ok, handler(), bindings(), meta()} | {error, not_found} | {error, {method_not_allowed, [method()]}}.
Look up a route by method and path.
-spec new() -> router().
Empty router with no routes.