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. }));
5. app.get('/header', ioc((@Header('x-foo') String header) {
6. return header;
7. }));
9. app.get('/query', ioc((@Query('q') String query) {
10. return query;
11. }));
13. app.get('/session', ioc((@Session('foo') String foo) {
14. return foo;
15. }));
17. app.get('/match', ioc((@Query('mode', match: 'pos') String mode) {
18. return 'YES $mode';
19. }));
21. app.get('/match', ioc((@Query('mode', match: 'neg') String mode) {
22. return 'NO $mode';
23. }));
25. app.get('/match', ioc((@Query('mode') String mode) {
26. return 'DEFAULT $mode';
27. }));
@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:
defaultValuerequired- custom
errormessage
<https://www.dartdocs.org/documentation/angel_framework/latest/angel_framework/Parameter-class.html>
