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

outdated

A simple dart http server in Koa2 style. Use with dia_router, dia_static, dia_body and other packages

Dia #

Pub Package GitHub Repo stars

A simple dart http server like KoaJS.

This package allows you to create a http / http server in a couple of lines. Dia creates a context from a bunch of request and response and passes it through the middleware.

The main idea of the project is minimalism. The package contains only basic functionality, everything else is implemented in separate packages. This allows you to keep the project code clean and connect only those dependencies that are really needed in it.

Usage: #

A simple usage example:

import 'package:dia/dia.dart';

main() {
  final app = 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 HttpRequest 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 more details, please, see example and test 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. Use with dia_router, dia_static, dia_body and other packages

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on dia