requiredBinding top-level constant Null safety

RequiredBinding const requiredBinding

Marks an ResourceController property binding as required.

Bindings are often applied to operation method arguments, in which required vs. optional is determined by whether or not the argument is in required or optional in the method signature.

When properties are bound, they are optional by default. Adding this metadata to a bound controller property requires that it for all operation methods.

For example, the following controller requires the header 'X-Request-ID' for both of its operation methods:

    class UserController extends ResourceController {
      @requiredBinding
      @Bind.header("x-request-id")
      String requestID;

      @Operation.get('id')
      Future<Response> getUser(@Bind.path("id") int id) async
         => return Response.ok(await getUserByID(id));

      @Operation.get()
      Future<Response> getAllUsers() async
         => return Response.ok(await getUsers());
    }

Implementation

const RequiredBinding requiredBinding = RequiredBinding();