package:angel_framework has nice support for injecting values from HTTP headers, query string, and session/cookie values, as well as pattern-matching for request handlers.

These act as a clean shorthand for commonly-usedfunctionality.

Here is a simple example of each of them in action:

  1. app.get('/cookie', ioc((@CookieValue('token') String jwt) {
  2. return jwt;
  3. }));
  4. app.get('/header', ioc((@Header('x-foo') String header) {
  5. return header;
  6. }));
  7. app.get('/query', ioc((@Query('q') String query) {
  8. return query;
  9. }));
  10. app.get('/session', ioc((@Session('foo') String foo) {
  11. return foo;
  12. }));
  13. app.get('/match', ioc((@Query('mode', match: 'pos') String mode) {
  14. return 'YES $mode';
  15. }));
  16. app.get('/match', ioc((@Query('mode', match: 'neg') String mode) {
  17. return 'NO $mode';
  18. }));
  19. app.get('/match', ioc((@Query('mode') String mode) {
  20. return 'DEFAULT $mode';
  21. }));

@Header()

A simple parameter annotation to inject the value of a sent HTTP header. Throws a 400 if the header is absent.

@Query()

Searches for the value of a query parameter.

@Session()

Fetches a value from the session.

@CookieValue()

Gets the value of a cookie.

@Parameter()

The base class driving the above matchers.

Supports:

  • defaultValue
  • required
  • custom error message

https://www.dartdocs.org/documentation/angel_framework/latest/angel_framework/Parameter-class.html