Bind.path constructor Null safety
- String? name
Binds a route variable from RequestPath.variables to an ResourceController operation method argument.
Routes may have path variables, e.g., a route declared as follows has an optional path variable named 'id':
router.route("/users/[:id]");
A operation method is invoked if it has exactly the same path bindings as the incoming request's path variables. For example, consider the above route and a controller with the following operation methods:
class UserController extends ResourceController {
@Operation.get()
Future<Response> getUsers() async => Response.ok(getAllUsers());
@Operation.get('id')
Future<Response> getOneUser(@Bind.path("id") int id) async => Response.ok(getUser(id));
}
If the request path is /users/1, /users/2, etc., getOneUser
is invoked because the path variable id
is present and matches
the Bind.path argument. If no path variables are present, getUsers
is invoked.
Implementation
const Bind.path(this.name)
: bindingType = BindingType.path,
accept = null,
require = null,
ignore = null,
reject = null;