dia 0.0.6 copy "dia: ^0.0.6" to clipboard
dia: ^0.0.6 copied to clipboard

outdated

A simple dart http server in Koa2 style. WARNING do not use it in production! It is alfa version and they need in more work!

A simple dart http server in Koa2 style.

This package is a wrapper over dart:io.HttpServer and allows you to create a queue of Middlewares. Each Middleware accepts a Context as its first argument, which can change, and as a second argument, a Future to the next Middleware, which allows you to wait for the execution of the following Middleware after the current one.

Usage: #

A simple usage example:

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

main() {
  final app = dia.App();
  
  app.use((ctx,next) async {
    ctx.body = 'Hello world!';
  });

  app
      .listen('localhost', 8080)
      .then((info) => print('Server started on http://localhost:8080'));
}

Context contain getters and setters for Request fields response, response.headers, response.headers.contentType, response.statusCode, that allow use it easy. Context contain method throwError that allow easy return HTTP errors by statusCode.

Example throwError:

    app.use((ctx,next) async {
      ctx.throwError(401);
    });

For details, please, see example folder.

Use with: #

  • dia_router - Package to route request as koa-router.
  • dia_cors - Package for CORS middleware.
  • dia_body - Package with the middleware for parse request body.
  • dia_static - Package to serving static files.

Features and bugs: #

I will be glad for any help and feedback! Please file feature requests and bugs at the issue tracker.

23
likes
0
pub points
74%
popularity

Publisher

verified publisherawcoding.com

A simple dart http server in Koa2 style. WARNING do not use it in production! It is alfa version and they need in more work!

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on dia