dia_router 0.1.7 copy "dia_router: ^0.1.7" to clipboard
dia_router: ^0.1.7 copied to clipboard

A router for Dia. Allow add dia middlewares for handle different url addresses.

example/dia_router_example.dart

import 'dart:io';

import 'package:dia/dia.dart';
import 'package:dia_router/dia_router.dart';

class ContextWithRouting extends Context with Routing {
  ContextWithRouting(HttpRequest request) : super(request);
}

void main() {
  /// create Dia app with Routing mixin on Context
  final app = App((request) => ContextWithRouting(request));

  /// create router and sub router
  final router1 = Router('/route');
  final router2 = Router('/subroute');

  /// add router middleware to app
  app.use(router1.middleware);

  /// add sub router middleware to router
  router1.use(router2.middleware);

  /// add handler to GET request
  router2.get('/data/:id', (ctx, next) async {
    ctx.body = '${ctx.params}';
  });

  /// start server
  app.listen('localhost', 8080).then((_) => print(
        'Router example start on http://localhost:8080/route/subroute/data/18',
      ));
}
1
likes
160
pub points
60%
popularity

Publisher

verified publisherawcoding.com

A router for Dia. Allow add dia middlewares for handle different url addresses.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

dia, path_to_regexp

More

Packages that depend on dia_router