Binds an HTTP request header to an HTTPController property or responder method argument.
This metadata may be applied to a responder method argument or a property of an HTTPController. When the incoming request
has a matching header name, the argument or property is set to the header's value.
For example, the following controller reads the header 'x-timestamp' into timestamp
for use
in the responder method:
class UserController extends HTTPController {
@httpGet
Future<Response> getUser(@HTTPHeader("x-timestamp") DateTime timestamp) async => ...;
}
The type of a bound property or argument must either be a String
or implement a static parse
method (e.g., int.parse
, DateTime.parse
).
If a declaration with this metadata is a positional argument in a responder method, it is required for that method.
e.g. the above example shows a required positional argument
If a declaration with this metadata is an optional argument in a responder method, it is optional for that method.
e.g. getUser({@HTTPHeader("x-timestamp") DateTime timestamp}) async => ...;
If a declaration with this metadata is a property without any additional metadata, it is optional for all methods in an HTTPController.
If a declaration with this metadata is a property with requiredHTTPParameter, it is required for all methods in an HTTPController.
Requirements that are not met will be evoke a 400 Bad Request response with the name of the missing header in the JSON error body. No responder method will be called in this case.
If not required and not present in a request, the bound arguments and properties will be null when the responder method is invoked.
- Inheritance
- Object
- HTTPBinding
- HTTPHeader
Constructors
- HTTPHeader(String header)
-
Binds an HTTP request header to an HTTPController property or responder method argument.
const
Properties
- type → String
-
@override, read-only
- externalName → String
-
The name of the variable in the HTTP request.
final, inherited - hashCode → int
-
The hash code for this object.
read-only, inherited - runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
Operators
-
operator ==(
other) → bool -
The equality operator.
inherited
Methods
-
parse(
ClassMirror intoType, Request request) → dynamic -
convertParameterListWithMirror(
List<String> parameterValues, TypeMirror typeMirror) → dynamic -
inherited
-
convertParameterWithMirror(
String parameterValue, TypeMirror typeMirror) → dynamic -
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed.
inherited -
toString(
) → String -
Returns a string representation of this object.
inherited