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