Binds an HTTP query parameter 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's Uri
has a matching query key, the argument or property is set to the query's value. Note that if the request is a POST with content-type 'application/x-www-form-urlencoded',
the query string included in the request body may still be bound to instances of this type.
For example, the following controller reads the query value 'since' into timestamp
for use
in the responder method (e.g., http://host.com/users?since=2017-08-04T00:00:00Z
class UserController extends HTTPController {
@httpGet
Future<Response> getUser(@HTTPQuery("since") DateTime timestamp) async => ...;
}
The type of a bound property or argument may either be a String
, bool
or implement a static parse
method (e.g., int.parse
, DateTime.parse
). It may also
be a List
of any of the allowed typed, for which each query key-value pair will be added to this list.
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({@HTTPQuery("since") 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
- HTTPQuery
Constructors
- HTTPQuery(String key)
-
Binds an HTTP request path query element 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