shelf_router_macro 0.0.0-dev.4
shelf_router_macro: ^0.0.0-dev.4 copied to clipboard
Experimental Dart package that is a thin wrapper for shelf_router using macros
shelf_router_macro #
π§ Experimental support for shelf_router using macros.
π Features #
- β¨ Route declarations
- β¨ Route parameters
- β¨ Lightweight - no additional dependencies beyond
shelf_router - ποΈ In Progress Intuitive - custom return types
- ποΈ In Progress Minimalistic - no need to specify
Request/Response, just return response body
π§βπ» Example #
import 'package:data_class_macro/data_class_macro.dart';
@Controller()
class GreetingController {
@Get('/<name>')
Response greetingByName(Request request, String name) {
return Response.ok('Hello, $name!');
}
// you can also omit Request/Response
// WARNING: only String return type is supported for now
@Get('/wave')
String wave() {
return '_o/';
}
}
void main() async {
final controller = GreetingController();
unawaited(
serve(controller.router, 'localhost', 8080),
);
print('β
Server listening on http://localhost:8080/');
print('π Testing...');
(await (await HttpClient().get('localhost', 8080, '/eeqk')).close())
.transform(utf8.decoder)
.listen(print); // Hello, eeqk!
}
π Quick Start #
Important
This package requires Dart SDK >= 3.5.0-164.0.dev
-
Download Dart from
devormasterchannel- Dart SDK archive
- dvm: Dart Version Manager
- Alternatively, you can simply switch to flutter master channel:
$ flutter channel master -
Add
package:shelf_router_macroto yourpubspec.yaml$ dart pub add shelf_router_macro -
Enable experimental macros in
analysis_options.yamlanalyzer: enable-experiment: - macros -
Use annotations provided by this library (see above example).
-
Run it
$ dart --enable-experiment=macros run lib/main.dart