WidgetRoute class abstract

A WidgetRoute is the most convenient way to create routes in your server. Override the build method and return an appropriate WebWidget.

By default, a WidgetRoute only responds to GET requests. To support additional HTTP methods like POST, pass them in the constructor:

class FormRoute extends WidgetRoute {
  FormRoute() : super(methods: {Method.get, Method.post});

  @override
  Future<WebWidget> build(Session session, Request request) async {
    if (request.method == Method.post) {
      // Handle form submission
      return SuccessWidget();
    }
    // Show form
    return FormWidget();
  }
}
Inheritance

Constructors

WidgetRoute({Set<Method> methods = const {Method.get}, String path = '/', String? host})
Creates a new WidgetRoute.

Properties

asHandler Handler
Returns this HandlerObject as a Handler.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
host String?
The virtual host this route will respond to.
finalinherited
methods Set<Method>
The methods this route will respond to, i.e. HTTP get or post.
finalinherited
path String
The suffix path this route will respond to.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

build(Session session, Request request) Future<WebWidget>
Override this method to build your web widget from the current session and request.
call(Request req) Future<Result>
Handles a call to this route, by extracting Session from request and forwarding to handleCall.
inherited
handleCall(Session session, Request req) FutureOr<Result>
Handles a call to this route.
override
injectIn(RelicRouter router) → void
Adds this handler to the given router with Method.get and path '/' Override to add differently.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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