https://github.com/redroserade/gladius
A basic, middleware-based application that runs on top of a dart HttpServer. Heavily inspired by Express JS and OWIN.
https://github.com/redroserade/gladius
Last synced: 8 months ago
JSON representation
A basic, middleware-based application that runs on top of a dart HttpServer. Heavily inspired by Express JS and OWIN.
- Host: GitHub
- URL: https://github.com/redroserade/gladius
- Owner: RedRoserade
- Created: 2015-01-10T15:56:53.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-01-17T14:51:06.000Z (over 11 years ago)
- Last Synced: 2025-03-16T13:37:07.582Z (over 1 year ago)
- Language: Dart
- Size: 164 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# gladius
A basic, middleware-based application that runs on top of a dart `HttpServer`. Heavily inspired by Express and OWIN. Not intended for use (at least, not yet).
## Usage
Similar to OWIN, this works based on request delegates and app functions.
An app function (`AppFunc`) is a function that uses a `Context` and returns a `Future`.
A request delegate is a function that takes an `AppFunc` and returns an `AppFunc`,
and these are used to compose the request pipeline. The `AppFunc` that is received through
parameter is the next middleware in the pipeline.
There are many ways `next()` can be called. One can call it at the end of the method,
which means the only processing done will be in the inbound request, before it's passed along.
It can also be called in the "middle" of the method (see below). This can be used for logging,
or error handling. One can also call it immediately, and have the middleware process the response
itself (for example, compression).
Of course, one can also not call `next()` at all, in which, the pipeline is short-circuited,
the preceeding middleware finishes processing, and the response is sent.
```dart
main() {
var app = new HttpApp();
app.address = '0.0.0.0';
app.port = 8080;
// A simple request logger.
// Here, next() is called in the middle of
// the method, so that timing can be done.
app.use((AppFunc next) => (Context ctx) async {
var sw = new Stopwatch();
sw.start();
await next(ctx);
sw.stop();
print('${ctx.request.method} ${ctx.request.path} - ${sw.elapsed.inMilliseconds}');
});
// A simple 'hello, world'. Since next() isn't
// called, the pipeline ends here.
// This is invoked when the logger calls next(),
// so, when this ends, the logger will continue execution.
app.use((AppFunc next) => (Context ctx) {
ctx.response.write('Hello, world!');
});
app.start();
}
```