RelicApp class final
The main application class for a Relic web server.
RelicApp extends RelicRouter and provides a convenient way to create, configure, and run a Relic HTTP server.
Virtual Host Routing
When useHostWhenRouting is true, the router prepends the request's
Host header to the path during route lookup. This enables virtual host
routing where different hosts can have different route handlers.
Routes should be registered with the host as the first path segment:
final app = RelicApp(useHostWhenRouting: true)
..get('api.example.com/users', apiUsersHandler)
..get('www.example.com/about', aboutHandler)
..get('*/health', healthHandler); // Matches any host
When useHostWhenRouting is false (the default), routing works as normal
using only the request path.
Hot Reload Support
When running with --enable-vm-service, RelicApp automatically listens for
hot-reload requests. When a hot reload is triggered, it will re-configure
the internal router with the latest route definitions.
This allows you to modify your route handlers and see the changes immediately without restarting the server. Note that this only works for changes to the route configuration and handlers - changes to server state or global variables may require a full restart.
- Implemented types
- Available extensions
Properties
- asHandler → Handler
-
Available on RelicRouter, provided by the RouterHandlerEx extension
Makes RelicRouter callable as a Handler.no setter -
delegate
↔ Router<
Handler> -
getter/setter pair
- fallback ↔ Handler?
-
The fallback value returned when no route matches the request path.
getter/setter pairoverride
- hashCode → int
-
The hash code for this object.
no setterinherited
- isEmpty → bool
-
Returns true if the router has no routes.
no setteroverride
- isSingle → bool
-
Returns true if the router has a single root route ('/').
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- useHostWhenRouting → bool
-
Whether to prepend the request's
Hostheader to the path during routing.final
Methods
-
add(
Method method, String path, Handler route) → void -
Adds a route definition to the router.
override
-
attach(
String path, RelicRouter subRouter, {bool consume = false}) → void -
Attaches a sub-router to this router at the specified
path.override -
call(
Request req) → FutureOr< Result> -
Available on RelicRouter, provided by the RouterHandlerEx extension
Similar to HandlerObject this extension allows a Router to be callable like a Handler. -
close(
) → Future< void> -
inject(
RouterInjectable injectable) → void -
Injects an
injectableinto the router. Unlike add it allows theinjectableobject to determine how to be mounted on the router.override -
lookup(
Method method, String path, {bool backtrack = true}) → LookupResult< Handler> -
Looks up a route matching the provided
path.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
run(
FutureOr< Adapter> adapterFactory(), {int noOfIsolates = 1, bool backtrack = true}) → Future<RelicServer> - Creates and starts a RelicServer with the configured routes.
-
serve(
{InternetAddress? address, int port = 8080, SecurityContext? securityContext, int backlog = 0, bool v6Only = false, int noOfIsolates = 1}) → Future< RelicServer> -
Available on RelicApp, provided by the RelicAppIOServeEx extension
Starts a HttpServer that listens on the specifiedaddressandportand sends requests tohandler. -
toString(
) → String -
A string representation of this object.
inherited
-
use(
String path, Middleware map) → void -
Adds a middleware function to the router.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited