steward 0.0.4 copy "steward: ^0.0.4" to clipboard
steward: ^0.0.4 copied to clipboard

outdated

Steward is a CLI and Framework for building expressive web servers in Dart.

Steward

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!

Note: As of 0.0.2, 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 :)

Steward is (somewhat) composable. If you only want to use the Router, you can only use the router. If you want to use the whole framework, that works too! Of course, there are some things that don't make sense to be used alone (Controllers, for example).

Using the entire framework together (the App) gives you the following (but not limited to) benefits:

  • First class support (this is the way we use Steward too!)
  • A modular system with light Dependency Injection, Routing, Controllers, and more.
  • Templating via the Mustache template specification.

Here's an example of how you can use Steward!

import 'package:steward/steward.dart';

// You can pull me out to a separate file, too ya know ;)
class SampleController extends Controller {
  @Injectable('UserService')
  late UserService userService;
  
  @Get('/version')
  version(_) => 'v1.0';

  @Get('/show')
  Response show(Request request) => view('main_template');
  
  @Get('/users')
  Response users => UserService.getUsers();
}

Future main() async {
  var router = Router();
  var container = CacheContainer();
  
  // Setup a DI binding for UserService
  container.bind('UserService', (_) => UserService());
  
  // Replace the default DI container implementation
  router.setContainer(container)
  
  // Mount the controller, parsing the annotations to build paths and injecting injectables
  router.mount(SimpleController);
  
  // Bare route handler example
  router.get('/hello', (_) {
    return Response.Ok('Hello World!');
  });
  
  // Plucking things out of the container example
  router.get('/config', (Request request) {
    print(request.container);
    print(request.container.make('@config'));
    return Response.Ok(request.container.make('@config'));
  });
  
  // Path Params example
  router.get('/:name', (Request request) {
    return Response.Ok(request.pathParams['name']);
  });
  
  var app = App(router: router, container: container);
  return app.start();
}
3
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Steward is a CLI and Framework for building expressive web servers in Dart.

Repository

License

unknown (LICENSE)

Dependencies

bosun, flat, mustache_template, path_to_regexp, yaml

More

Packages that depend on steward