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

hashCode int
The hash code for this object.
no setterinherited
mount String
finalinherited
name String
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

all(String pattern, ParamRequestHandler handler) RouterService
Registers a handler for any method on pattern.
delete(String pattern, ParamRequestHandler handler) RouterService
Registers a DELETE handler.
get(String pattern, ParamRequestHandler handler) RouterService
Registers a GET handler.
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 connection whose upgrade request matched 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) on pattern.
post(String pattern, ParamRequestHandler handler) RouterService
Registers a POST handler.
put(String pattern, ParamRequestHandler handler) RouterService
Registers a PUT handler.
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