serral 0.1.9 copy "serral: ^0.1.9" to clipboard
serral: ^0.1.9 copied to clipboard

outdated

Fast and productive web server framework provided by Dart, like Koa. Easy add middleware at before request and after request. Easy extend context Type and values.

example/example.dart

import 'package:serral/main.dart';

void main() {
  final app = Serral();
  app.serve(port: 5100);

  // open cros
  app.before(app.addCorsHeaders);

  app.before((SerralCtx ctx) {
    print(ctx.request.uri.toString());
    ctx.context['dog'] = 100;
  });

  app.after((SerralCtx ctx) {
    print('end');
  });

  app.GET('/', getHome);
  app.POST('/dog', postDog);
}

void getHome(SerralCtx ctx) async {
  // read ctx.context, check app.before;
  print(ctx.context['dog']);
  ctx.send(200, 'hello: ${ctx.context['dog']}');
}

void postDog(SerralCtx ctx) async {
  print(ctx.body);
  // use Futrue, check app.after;
  await Future.delayed(Duration(milliseconds: 300));
  ctx.send(200, 'order');
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Fast and productive web server framework provided by Dart, like Koa. Easy add middleware at before request and after request. Easy extend context Type and values.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on serral