patch function
JetLeaf's Routing DSL provides a concise, functional way to create and register HTTP routes without explicitly instantiating Route or calling RouterBuilder.route manually.
Each function corresponds to a standard HTTP method (e.g. get, post)
and produces a preconfigured RouterBuilder containing a single route.
You can then:
- Chain additional routes with the builder API, or
- Compose routes together using
.and(),.group(), etc.
Example
import 'package:jetleaf/jetleaf.dart';
final router = get('/hello', (req) => 'Hello, JetLeaf!')
.and(post('/save', (req) => {'status': 'ok'}))
.and(getX('/ping', (req, res) async {
await res.getBody().writeString('pong');
}));
final spec = router.build();
for (final route in spec.routes) {
print('${route.method} ${route.path}');
}
Design
- Functions ending with
Xexpect a handler signature of(ServerHttpRequest, ServerHttpResponse) - Non-
Xvariants expect(ServerHttpRequest) - Each returns a RouterBuilder containing one route definition.
Implementation
RouterBuilder patch(String path, RequestRouterFunction handler) =>
RouterBuilder()..route(PATCH(path), handler);