RouterService class
A Service that dispatches to sub-routes by HTTP method and a
PathPattern, exposing captured path parameters — the intra-service
equivalent of shelf_router, without leaving the HubRequest/HubResponse
model.
final api = RouterService(name: 'drive', mount: '/drives')
..get('/drives/<endpoint>/<name>', (req, p) async =>
HubResponse.json({'drive': '${p['endpoint']}/${p['name']}'}))
..get('/drives/<endpoint>/<name>/files/<path|.*>', (req, p) async =>
serveFile(p['endpoint']!, p['name']!, p['path']!));
hub.registerService(api);
A path that matches a pattern but not its method yields 405; no match at
all yields 404. Captured params are also stored in
request.context['params'].
Constructors
- RouterService({required String name, String mount = '/'})
-
Creates a router service mounted at
mount.
Properties
Methods
-
all(
String pattern, ParamRequestHandler handler) → RouterService -
Registers a handler for any method on
pattern. -
delete(
String pattern, ParamRequestHandler handler) → RouterService -
Registers a
DELETEhandler. -
get(
String pattern, ParamRequestHandler handler) → RouterService -
Registers a
GEThandler. -
handle(
HubRequest request) → Future< HubResponse> -
Handles an ordinary request. The service receives the full
request(its path is not stripped of mount). -
handleConnection(
Connection connection, HubRequest request) → FutureOr< void> -
Handles an upgraded WebSocket
connectionwhose upgraderequestmatched this service. Services that do not serve WebSockets should close the connection.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
on(
String method, String pattern, ParamRequestHandler handler) → RouterService -
Registers a handler for
method(upper-cased) onpattern. -
post(
String pattern, ParamRequestHandler handler) → RouterService -
Registers a
POSThandler. -
put(
String pattern, ParamRequestHandler handler) → RouterService -
Registers a
PUThandler. -
start(
) → Future< void> -
Starts the service (open resources, connect to backends, ...). Called by
the hub on OmnyHub.start or when registered into a running hub.
inherited
-
stop(
) → Future< void> -
Stops the service and releases its resources.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited