Bind.body constructor Null safety
Binds an HTTP request body to an ResourceController property or operation method argument.
The body of an incoming request is decoded into the bound argument or property. The argument or property must implement Serializable or be a List<Serializable>. If the property or argument is a List<Serializable>, the request body must be able to be decoded into a List of objects (i.e., a JSON array) and Serializable.read is invoked for each object (see this method for parameter details).
Example:
class UserController extends ResourceController {
@Operation.post()
Future<Response> createUser(@Bind.body() User user) async {
final username = user.name;
...
}
}
If the bound parameter is a positional argument in a operation method, it is required for that method. If the bound parameter is an optional argument in a operation method, it is optional for that method. 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.
Requirements that are not met will be throw a 400 Bad Request response with the name of the missing header in the JSON error body. No operation 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 operation method is invoked.
Implementation
const Bind.body({this.accept, this.ignore, this.reject, this.require})
: name = null,
bindingType = BindingType.body;