Bind.header constructor Null safety
- String? name
Binds an HTTP request header to an ResourceController property or operation method argument.
When the incoming request has a header with the name name,
the argument or property is set to the headers's value. For example,
a request with the header Authorization: Basic abcdef
would bind the value Basic abcdef
to the authHeader
argument:
@Operation.get()
Future<Response> getUsers(@Bind.header("Authorization") String authHeader) async => ...;
name is compared case-insensitively; both Authorization
and authorization
will match the same header.
Parameters with this metadata may be String, bool, or any type that implements parse
(e.g., int.parse or DateTime.parse).
If the bound parameter is a positional argument in a operation method, it is required for that method. A 400 Bad Request will be sent and the operation method will not be invoked if the request does not contain the header.
If the bound parameter is an optional argument in a operation method, it is optional for that method. The value of the bound property will be null if it was not present in the request.
If the bound parameter is a property without any additional metadata, it is optional for all methods in an ResourceController. If the bound parameter is a property with requiredBinding, it is required for all methods in an ResourceController.
Implementation
const Bind.header(this.name)
: bindingType = BindingType.header,
accept = null,
require = null,
ignore = null,
reject = null;