Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getParams method to router.dart #453

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added Tests and Changelog
  • Loading branch information
CLNMR committed Oct 31, 2024
commit 084d7222f2c2f457d664891fc0ca70afb8ead9de
4 changes: 4 additions & 0 deletions pkgs/shelf_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.6

* Added function `getParams` to the `Router` class to get the parameters from a request

## 1.1.5-wip
CLNMR marked this conversation as resolved.
Show resolved Hide resolved

* Require Dart `^3.3.0`.
Expand Down
15 changes: 15 additions & 0 deletions pkgs/shelf_router/test/router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ void main() {
expect(await get('/user/jonasfj/groups/42'), 'jonasfj / 42');
});

test('get params via getParams', () async {
var app = Router();

app.get(
r'/user/<user>/groups/<group|\d+>',
(Request request) => Response.ok(''),
);

final params =
app.getParams(Request('GET', Uri.http('', '/user/jonasfj/groups/42')))!;

expect(params['user'], 'jonasfj');
expect(params['group'], '42');
});

test('params by arguments', () async {
var app = Router();

Expand Down
Loading