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.
Install:
Add to pubspec.yaml in dependencies section this:
Then run pub get
Usage:
A simple usage example:
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
:
You can use custom Context
with additional fields and methods. In this case, you need to inherit from the base Context and pass the instance of context creation function to the App constructor.
Your can add handler to all Http errors:
You can start your server with SSL:
For more details, please, see example and test folder.