jaguar_resty 1.1.0-dev2 jaguar_resty: ^1.1.0-dev2 copied to clipboard
Build fluent functional Restful clients
example/jaguar_resty_example.dart
import 'dart:async';
import 'package:jaguar_resty/jaguar_resty.dart' as resty;
import 'package:jaguar/jaguar.dart';
class Book {
String id;
String name;
Book({this.id, this.name});
static Book map(Map map) => new Book()..fromMap(map);
Map get toMap => {
'id': id,
'name': name,
};
void fromMap(Map map) => this
..id = map['id']
..name = map['name'];
}
final books = <Book>[
new Book(id: '1', name: 'Harry potter'),
new Book(id: '2', name: 'Da Vinci code'),
new Book(id: '3', name: 'Angels and deamons'),
];
Future serve() async {
final server = new Jaguar(port: 8000);
server.getJson(
'/book/:id',
(Context ctx) => books
.firstWhere((b) => b.id == ctx.pathParams['id'], orElse: () => null)
?.toMap);
server.postJson('/book', (Context ctx) async {
// TODO books.add(await ctx.req.bo);
});
// TODO
server.log.onRecord.listen(print);
await server.serve(logRequests: true);
}
Future client() async {
// TODO
}
main() async {
/*
await serve();
await client();
*/
assert("Whatever" == "Not whatever");
resty.get('/book').fetchResponse;
}