Handles class

Annotation for a request handler.

Instances of this class is designed to be used as an annotation on a top-level function or static member that act as request handlers.

Annotating request handlers

Use the convenience constructors Handles.get, Handles.post, Handles.put etc. that are named after a standard HTTP method; or the generic Handles.request constructor that supports any HTTP method.

The httpMethod is the HTTP request method that the rule will handle. It is a string such as "GET" or "POST".

The ServerPipeline it is for is identified by the pipeline. The order for the rule is determined by the priority and then the pattern. Normally, the priority does not need to be changed from the default of zero, since sorting by the pattern usually produces a correctly working pipeline.

For example, used as an annotation on a top-level function, for the default pipeline:

@Handles.get('~/foo/bar')
Future<Response> myBarHandler(Request req) {
  ...
}

Usage as an annotation on a static method, for a named pipeline:

class SomeClass {

  @Handles.post('~/foo/bar/baz', pipeline='mySpecialPipeline')
  static Future<Response> myPostHandler(Request req) {
    ...
  }
}

Normally, the priority can be left as the default, since sorting by the pattern should produce a properly functioning pipeline. See the Pattern.compareTo operator for how patterns are ordered. For special situations, the priority can be set to a non-zero value; but multiple pipelines can also be used to achieve the same behaviour.

Logging

The "woomera.handles" logger is used for Handles related log entries.

  • CONFIG: shows only the number of annotations found
  • FINE: lists what they handle
  • FINER: lists what they handle and the request handler that was annotated
  • FINEST: also logs the libraries that were scanned for annotations

Note: the above logs the Handles annotations that were found, but they will only be used if a pipeline was created with the same name (i.e. via the ServerPipeline constructor or Server constructor).

Inheritance

Constructors

Handles.delete(String? pattern, {String? pipeline, int? priority})
Constructor with the HTTP DELETE method.
const
Handles.exceptions()
Constructor for server exception handler annotation.
const
Handles.get(String? pattern, {String? pipeline, int? priority})
Constructor with the HTTP GET method.
const
Handles.head(String? pattern, {String? pipeline, int? priority})
Constructor with the HTTP HEAD method.
const
Handles.patch(String? pattern, {String? pipeline, int? priority})
Constructor with the HTTP PATCH method.
const
Handles.pipelineExceptions({String? pipeline})
Constructor for pipeline exception handler annotations.
const
Handles.post(String? pattern, {String? pipeline, int? priority})
Constructor with the HTTP POST method.
const
Handles.put(String? pattern, {String? pipeline, int? priority})
Constructor with the HTTP PUT method.
const
Handles.rawExceptions()
Constructor for low-level server exception handler annotation.
const
Handles.request(String? httpMethod, String? pattern, {String? pipeline, int? priority})
Constructor with an explicitly specified HTTP method.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
httpMethod String?
The HTTP method for the server rule.
final
isPipelineExceptionHandler bool
Indicates if this is describing a pipeline exception handler
no setter
isRequestHandler bool
Indications if this is describing an exception handler or not. Indications if this is describing a request handler or not.
no setter
isServerExceptionHandler bool
Indicates if this is describing a server exception handler
no setter
isServerRawExceptionHandler bool
Indicates if this is describing a server raw exception handler
no setter
pattern String?
The string representation of the pattern for the server rule.
final
pipeline String?
Name of the pipeline.
final
priority int?
The priority for the rule within the pipeline.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

handlerWrapper HandlerWrapper?
Wrapper for the annotated function.
getter/setter pair