dia 0.0.7 dia: ^0.0.7 copied to clipboard
A simple dart http server in Koa2 style. Use with dia_router, dia_static, dia_body and other packages
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.