steward 0.4.0 steward: ^0.4.0 copied to clipboard
Steward is a CLI and Framework for building expressive web servers in Dart.
A helpful framework for building server-side experiences with Dart.
Steward features a command line interface for starting a new Steward project! Check it out!
dart pub global activate steward
Note: Steward uses a config yml file that is generated by the CLI. If you choose to not use the CLI, you'll need to generate a matching config.yml file.
The best examples for how to use Steward are captured in the test folder. Eventually, we'll refactor this out into tests and examples separately, but for now, they live together :)
Using the Steward framework gives you the following (but not limited to) benefits:
- A modular system with light Dependency Injection, Routing, and more.
- Easy HTTP request/response management.
- Config parsing into the DI container at application boot.
- Templating via the Mustache template specification.
Here's an example of how you can use Steward!
import 'package:steward/steward.dart';
Future main() async {
final router = Router();
final container = Container();
// Setup a DI binding for UserService
container.bind('UserService', (_) => UserService());
// Replace the default DI container implementation
router.setContainer(container);
// Bare route handler example
router.get('/hello', (_) {
return Response.Ok('Hello World!');
});
// Plucking things out of the container example
router.get('/config', (Context context) {
print(context.make('@config.app.name'));
return Response.Ok(context.make('@config.app.name'));
});
// Path Params example
router.get('/:name', (Context context) {
return Response.Ok(context.request.pathParams['name']);
});
var app = App(router: router);
return app.start();
}