Middleware class

A process performed on a Request before a Handler (a RequestMiddleware) and/or on a Response after a Handler (a ResponseMiddleware).

A Handler can also be provided in case of an error in the Middleware execution.

Middleware is added to a Request/Response Pipeline and can be synchronous where runAsync is false or asynchronous where runAsync is true. Middleware can be forced to run when useAlways is set to true; this is helpful for Middleware such as loggers, which should always run regardles of the Request/Response status.

Synchronous Middleware are not guaranteed to run if a prior Middleware aborts the Request/Response and useAlways is false. Asynchronous Middleware are not guaranteed to run if a sibling asynchronous Middleware finishes first and aborts the Request/Response. Asynchronous Middleware may complete in any order so they should be used carefully; generally not to modify the Request/Response if other asynchronous Middleware depend on the modification or to spawn related but independent processes such as storing a request count to a database or retrieving multiple services a handler might depend on.


Middleware({RequestMiddleware onRequest, ResponseMiddleware onResponse, Handler error, bool runAsync: false, bool useAlways: false})
Each Middleware is provided an optional RequestMiddleware, ResponseMiddleware, and error Handler. Additional parameters runAsync and useAlways determine how the Middleware will be applied to the Pipeline.


errorHandler Handler
hashCode int
The hash code for this object. [...]
read-only, inherited
requestMiddleware RequestMiddleware
responseMiddleware ResponseMiddleware
runAsync bool
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
useAlways bool


noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toString() String
Returns a string representation of this object.


operator ==(Object other) bool
The equality operator. [...]