Pattern Matching and Parameter
package:angel3_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:
1
app.get('/cookie', ioc((@CookieValue('token') String jwt) {
2
return jwt;
3
}));
4
​
5
app.get('/header', ioc((@Header('x-foo') String header) {
6
return header;
7
}));
8
​
9
app.get('/query', ioc((@Query('q') String query) {
10
return query;
11
}));
12
​
13
app.get('/session', ioc((@Session('foo') String foo) {
14
return foo;
15
}));
16
​
17
app.get('/match', ioc((@Query('mode', match: 'pos') String mode) {
18
return 'YES $mode';
19
}));
20
​
21
app.get('/match', ioc((@Query('mode', match: 'neg') String mode) {
22
return 'NO $mode';
23
}));
24
​
25
app.get('/match', ioc((@Query('mode') String mode) {
26
return 'DEFAULT $mode';
27
}));
Copied!

@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
Last modified 4mo ago