Skip to content

Commit

Permalink
Add getParams method to router.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
CLNMR committed Oct 26, 2024
1 parent f560053 commit 9c3c064
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkgs/shelf_router/lib/src/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@ class Router {
return _notFoundHandler(request);
}

/// Get URL parameters captured by the [Router].
/// Returns `null` if no parameters are captured.
Map<String, String>? getParams(Request request) {
for (var route in _routes) {
if (route.verb != request.method.toUpperCase() && route.verb != 'ALL') {
continue;
}
var params = route.match('/${request.url.path}');
if (params != null) {
return params;
}
}
return null;
}

// Handlers for all methods

/// Handle `GET` request to [route] using [handler].
Expand Down

0 comments on commit 9c3c064

Please sign in to comment.