allowMethod method

bool allowMethod()

Validates if the current HTTP request method is allowed for this route.

Checks the incoming request's HTTP method against the route's configured allowed methods list. This is used during the routing process to determine if a route should handle a specific request.

Returns true if the request method is in the methods list, false otherwise.

Example:

// Route configured for GET and POST
final route = WebRoute(
  path: '/api/users',
  methods: [RequestMethods.GET, RequestMethods.POST],
);

// For a GET request: returns true
// For a DELETE request: returns false

Implementation

bool allowMethod() {
  return (methods.contains(Context.rq.method));
}