Pattern Matching and Parameter

Last updated 6 months ago

As of 1.1.0, 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-used functionality.

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

app.get('/cookie', (('token') String jwt) {
return jwt;
});
app.get('/header', (('x-foo') String header) {
return header;
});
app.get('/query', (('q') String query) {
return query;
});
app.get('/session', (('foo') String foo) {
return foo;
});
app.get('/match', (('mode', match: 'pos') String mode) {
return 'YES $mode';
});
app.get('/match', (('mode', match: 'neg') String mode) {
return 'NO $mode';
});
app.get('/match', (('mode') String mode) {
return 'DEFAULT $mode';
});

@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/1.1.1/angel_framework/Parameter-class.html