pneuma 0.4.0

  • Readme
  • Changelog
  • Installing
  • 37

Pneuma #

The vital spirit, soul, or creative force of a person.
"In Stoic philosophy, the pneuma penetrates all things, holding things together."

Basically, yet another server framework, that provides middleware architecture and possibility to write MVC backend applications. Fast and very simple. Kickoff in a minute. If you used expressjs before then this framework will not be hard for you to understand.

Installation & setup

Put dart_pneuma package into your pubspec.yaml dependencies section and run pub get. Import the dependency inside your main file

import 'package:pneuma/pneuma.dart';

void main() {
  Pneuma app = new Pneuma();


This will start basic http server on default host and port You can either provide host and port named parametes into the constructor or use environment variables: IP and PORT

Usage #

Pneuma could be used in three ways:

  1. Writing routed handlers
  2. Using middlewares
  3. Writing controllers with route maps

Writing routed handlers #

Idea is the same as in nodejs's expressjs library. You can just map paths to a specific handler which will process the request or pass it forward by calling next callback.

import 'package:pneuma/pneuma.dart';

final RegExp allRoutes = new RegExp('.*');

void main() {
  Pneuma app = new Pneuma()
    ..get('/user', (req, res, next) {
      res.send('Hello user');
    .post('/user', (req, res, next) async {
      dynamic body = await req.body;
      res.send('User has been updated');
    .match(allRoutes, (req, res, next) {
      res.send('Not found');


Using middlewares #

Middleware abstract class should be extended to create your middleware. You will need to override run method, which will receive Request and Response instances as an arguments and should return Future of null or next Middleware usually accessible with property, as Middleware is LinkedListEntity

import 'package:pneuma/pneuma.dart';

class LogMiddleware extends Middleware {
  Future<Middleware> run(Request req, Response res) {
    DateTime start = new;
    res.done.then((_res) {
      DateTime sent = new;
      String stamp = sent.toIso8601String();
      double timeTaken = (sent.millisecondsSinceEpoch - start.millisecondsSinceEpoch) / 1000;

      print('[$stamp]: ${} ${_res.statusCode} ${req.uri.toString()} took ${timeTaken} sec.');

    return new Future.value(;

void main() {
  Pneuma app = new Pneuma()
    ..use(new LogMiddleware())
    ..get('/user', (req, res, next) {
      res.send('Hello user');


Writing controllers with route map #

As once popular and still widely used, MVC architectural pattern is very usefull to build large scale applications. Extended from Middleware, Controller class can also be extended to let you map application routes to specific action methods, which should process the request as an endpoints of the app.

class UserController extends Controller {
  TestController() {
    routeMap = {
      new RegExp(r'^\/user'): indexAction,

  void indexAction(Request req, Response res) {
    res.send('Index Page');

void main() {
  Pneuma app = new Pneuma()
    ..use(new UserController());


routeMap is a Map<RegExp, Invocation> which, in oreder for actions to be mapped to specified paths, should be defined.

Next step for the controllers will be defining annotations to marks actions for a specific route in a more friendlier manner.

class UserController extends Controller {
  void indexAction(Request req, Response res) {
    res.send('Index Page');
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](
and this project adheres to [Semantic Versioning](

## [0.3.4] - 2019-03-04
### Fixed
- Dart native response close handling. Was getting error on trying to process thrown exception

## [0.3.3] - 2019-03-03
### Updated
- Access additional parameters via [] operator

### Fixed
- Content type of type string

## [0.3.2] - 2019-03-03
### Added
- Store additional parameters for request in Map `req.additionalParams`

## [0.3.1] - 2019-03-03
### Added
- ip to Request from connectionInfo

## [0.3.0] - 2018-08-17
### Changed
- Pneuma server get/post/etc shortcut methods accepts dynamic as handler. Could be middleware
- Controller now passes matched params as an arguments aside of req, and res

## [0.2.5] - 2018-08-15
### Added
- Response timeout added

### Fixed
- Adding default headers before app start
- Controller routes fixed

## [0.2.4] - 2018-08-15
### Added
- Added ServerStatus to Pneuma
- On start and server error handling
- ServerStatus stream

### Changed
- Updated HttpHeaders to dart 2 for Response

## [0.2.2] - 2018-08-14
### Added
- request headers

## [0.2.1] - 2018-08-14
### Added
- `stop` for Pneuma instance to stop HttpServer
- methods to controll HttpServer#defaultHeaders

## [0.2.0] - 2018-08-14
### Changed
- Updated to dart version 2

## [0.1.0] - 2018-08-06
### Added
- Middleware as an interface
- Controller to work in MVC kind of manner
- example dir with example

### Changed
- Future based middleware chain

### Removed
- Custom events class
- waterfall recurcive middleware handling
- Log to be a separate middleware

## [0.0.3] - 2015-08-16
### Added
- Initial structure
- Event based controllers concept
- MiddlewareHandler through a waterfall recurcive stack

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  pneuma: ^0.4.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:pneuma/pneuma.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Dec 18, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.2

Health issues and suggestions

Document public APIs. (-0.49 points)

114 out of 116 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/app.dart. (-13.09 points)

Analysis of lib/src/app.dart reported 28 hints, including:

line 24 col 60: Unnecessary new keyword.

line 26 col 23: Private field could be final.

line 26 col 34: Use collection literals when possible.

line 26 col 34: Unnecessary new keyword.

line 29 col 37: Unnecessary new keyword.

Fix lib/src/controller.dart. (-4.89 points)

Analysis of lib/src/controller.dart reported 10 hints, including:

line 36 col 5: Omit type annotations for local variables.

line 39 col 14: Don't access members with this unless avoiding shadowing.

line 41 col 5: Omit type annotations for local variables.

line 44 col 10: Omit type annotations for local variables.

line 46 col 7: Omit type annotations for local variables.

Fix lib/src/response.dart. (-4.89 points)

Analysis of lib/src/response.dart reported 10 hints, including:

line 11 col 26: Unnecessary new keyword.

line 14 col 16: Private field could be final.

line 19 col 3: The method add should have a return type but doesn't.

line 20 col 3: The method addError should have a return type but doesn't.

line 31 col 49: Use = to separate a named parameter from its default value.

Fix additional 6 files with analysis or formatting issues. (-8.93 points)

Additional issues in the following files:

  • lib/src/middleware/conditional_middleware.dart (7 hints)
  • lib/src/errors.dart (4 hints)
  • lib/src/request.dart (3 hints)
  • lib/src/body.dart (2 hints)
  • lib/src/types.dart (2 hints)
  • lib/src/middleware.dart (Run dartfmt to format lib/src/middleware.dart.)

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and pneuma.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
http_server >=0.9.8 <1.0.0 0.9.8+3
Transitive dependencies
mime 0.9.6+3
path 1.6.4