jaguar_reflect 0.5.1 jaguar_reflect: ^0.5.1 copied to clipboard
Reflection based alternative for Jaguar
jaguar_reflect #
Uses reflection instead of source generation to serve Jaguar Api classes
Usage #
A simple usage example:
final book = new Book.make('0', 'Book1', ['Author1', 'Author2']);
@Api(path: '/api/book')
class BooksApi {
@Post()
Future<Response<String>> addBook(Context ctx) async {
// Decode request body as JSON Map
final Map<String, dynamic> json = await ctx.req.bodyAsJsonMap();
Book book = new Book()..fromMap(json);
print(book.toMap());
// Encode Map to JSON
return Response.json(book.toMap());
}
}
Future<Null> main(List<String> args) async {
Jaguar jaguar = new Jaguar();
jaguar.addApi(reflectJaguar(new BooksApi()));
await jaguar.serve();
}