2018-08-20 19:18:43 +00:00
|
|
|
import 'dart:math';
|
|
|
|
|
|
|
|
import 'package:angel_route/angel_route.dart';
|
|
|
|
|
|
|
|
main() {
|
2019-11-28 17:40:32 +00:00
|
|
|
final router = Router();
|
2018-08-20 19:18:43 +00:00
|
|
|
|
2019-02-03 05:33:47 +00:00
|
|
|
router.get('/whois/~:user', () {});
|
|
|
|
|
|
|
|
router.get('/wild*', () {});
|
|
|
|
|
2019-02-03 05:52:48 +00:00
|
|
|
router.get('/ordinal/int:n([0-9]+)st', () {});
|
2019-02-03 05:33:47 +00:00
|
|
|
|
|
|
|
print(router.resolveAbsolute('/whois/~thosakwe').first.allParams);
|
|
|
|
print(router.resolveAbsolute('/wild_thornberrys').first.route.path);
|
2019-02-03 05:52:48 +00:00
|
|
|
print(router.resolveAbsolute('/ordinal/1st').first.allParams);
|
2019-02-03 05:33:47 +00:00
|
|
|
|
2018-08-20 19:18:43 +00:00
|
|
|
router.get('/users', () {});
|
|
|
|
|
|
|
|
router.post('/users/:id/timeline', (String id) {});
|
|
|
|
|
|
|
|
router.get('/square_root/:id([0-9]+)', (String n) {
|
|
|
|
return {'result': pow(int.parse(n), 0.5)};
|
|
|
|
});
|
|
|
|
|
|
|
|
// You can also have parameters auto-parsed.
|
|
|
|
//
|
|
|
|
// Supports int, double, and num.
|
|
|
|
router.get('/square_root/int:id([0-9]+)', (int n) {
|
|
|
|
return {'result': pow(n, 0.5)};
|
|
|
|
});
|
|
|
|
|
|
|
|
router.group('/show/:id', (router) {
|
|
|
|
router.get('/reviews', (id) {
|
|
|
|
return someQuery(id).reviews;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Optionally restrict params to a RegExp
|
|
|
|
router.get('/reviews/:reviewId([A-Za-z0-9_]+)', (id, reviewId) {
|
|
|
|
return someQuery(id).reviews.firstWhere((r) => r.id == reviewId);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-11-28 17:40:32 +00:00
|
|
|
SomeQuery someQuery(id) => SomeQuery();
|
2018-08-20 19:18:43 +00:00
|
|
|
|
|
|
|
class SomeQuery {
|
|
|
|
List<SomeQueryReview> get reviews => [
|
|
|
|
SomeQueryReview('fake'),
|
|
|
|
SomeQueryReview('data'),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
class SomeQueryReview {
|
|
|
|
final String id;
|
|
|
|
|
|
|
|
SomeQueryReview(this.id);
|
|
|
|
}
|