spry_router 1.2.1 copy "spry_router: ^1.2.1" to clipboard
spry_router: ^1.2.1 copied to clipboard

discontinuedreplaced by: spry

A request router for the Spry web framework that supports matching handlers from path expressions.

example/main.dart

import 'package:spry/spry.dart';
import 'package:spry_router/spry_router.dart';

void main() async {
  final Spry spry = Spry();
  final Router router = Router();
  router.all('/', (context) {
    context.response.text('Hello World!');
  });
  router.get('/hello/:name', (Context context) {
    final String name = context.request.param('name') as String;

    context.response.text('Hello $name!');
  });

  final Router api = Router();
  api.get('/users', (Context context) {
    context.response.text('Users');
  });
  api.get('/users/:id', (Context context) {
    final String id = context.request.param('id') as String;

    context.response.text('User $id');
  });

  // Mount the API router to the `/api` path.
  router.mount('/api', router: api);

  // Mount a handler to the `/user` path.
  router.mount('/user', handler: (Context context) {
    context.response.text('User');
  });

  // Merge the API router into the main router.
  router.merge(api);

  await spry.listen(router, port: 3000);

  print('Listening on http://localhost:3000');
}
1
likes
140
points
111
downloads

Publisher

verified publisherodroe.com

Weekly Downloads

A request router for the Spry web framework that supports matching handlers from path expressions.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

http_methods, prexp, spry

More

Packages that depend on spry_router