tree: 68a1a01c2feea2c3538a777212e098af24425225 [path history] [tgz]
  1. example/
  2. lib/
  3. test/
  4. CHANGELOG.md
  5. LICENSE
  6. mono_pkg.yaml
  7. pubspec.yaml
  8. README.md
pkgs/shelf_router/README.md

pub package package publisher

Web Request Router for Shelf

Shelf makes it easy to build web applications in Dart by composing request handlers. This package offers a request router for Shelf, matching request to handlers using route patterns.

Also see the shelf_router_generator package for how to automatically generate a Route using the Route annotation in this package.

Example

import 'package:shelf_router/shelf_router.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;

// instantiate a router and configure your routes
var router = Router();

router.get('/hello', (Request request) {
  return Response.ok('hello-world');
});

router.get('/user/<user>', (Request request, String user) {
  return Response.ok('hello $user');
});

// use a Pipeline to configure your middleware,
// then add the router as the handler
final app = const Pipeline()
  .addMiddleware(logRequests())
  .addHandler(router);

var server = await io.serve(app, 'localhost', 8080);

See reference documentation of Router class for more information.

See also