tree: 874bafd5de70f8aa6390cb3d754639c70bf9469d [path history] [tgz]
  1. example/
  2. lib/
  3. test/
  4. analysis_options.yaml
  5. CHANGELOG.md
  6. LICENSE
  7. mono_pkg.yaml
  8. pubspec.yaml
  9. 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;

var app = Router();

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

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

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

See reference documentation of Router class for more information.

See also