shelf_router_macro

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

shelf router macro

shelf_router_macro #



🚧 Experimental support for shelf_router
using macros.
🌟 Features #

✨ Route declarations
✨ Route parameters
✨ Async routes
✨ 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

🧑‍💻 Examples #
import 'package:data_class_macro/data_class_macro.dart';

@Controller()
class GreetingController {
@Get('/wave')
Future<String> wave() async {
await Future.delayed(const Duration(seconds: 1));
return '_o/';
}
}
copied to clipboard
import 'package:json/json.dart';
import 'package:data_class_macro/data_class_macro.dart';

@JsonCodable()
class Pong {
Pong({required this.uid});

final String uid;
}

@Controller()
class PingController {
@Get('/ping/<uid>')
Future<Pong> ping(String uid) async {
return Pong(uid: uid);
}
}
copied to clipboard
🚀 Quick Start #

Important
This package requires Dart SDK >= 3.5.0-164.0.dev



Download Dart from dev or master channel

Dart SDK archive
dvm: Dart Version Manager
Alternatively, you can simply switch to flutter master channel:

$ flutter channel master
copied to clipboard


Add package:shelf_router_macro to your pubspec.yaml
$ dart pub add shelf_router_macro
copied to clipboard


Enable experimental macros in analysis_options.yaml
analyzer:
enable-experiment:
- macros
copied to clipboard


Use annotations provided by this library (see above example).


Run it
$ dart --enable-experiment=macros run lib/main.dart
copied to clipboard


🙌 Hands-on guide #
Defining routes: #
All routes should be declared as part of a class annotated with @Controller():
@Controller()
class SomeController {
@Get('/')
String health() => 'ok';
}
copied to clipboard
Customizing response: #
Return shelf's Response:
@Get('/')
String health() => Response.ok(
'ok',
headers: { 'X-Test': 'test' },
);
copied to clipboard
Accessing request details: #
Include shelf's Request in method signature:
@Get('/')
String test(Request r) => 'Headers: ${r.headers}';
copied to clipboard
===
TODO: add remaining examples.I've yet to decide on the format, I have to think about it some more.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.

Related Products

More From This Creator