platform/lib/src/http/service.dart

54 lines
1.5 KiB
Dart
Raw Normal View History

2016-04-18 03:27:23 +00:00
part of angel_framework.http;
/// A data store exposed to the Internet.
class Service extends Routable {
/// The [Angel] app powering this service.
Angel app;
2016-04-18 03:27:23 +00:00
/// Retrieves all resources.
Future<List> index([Map params]) {
throw new AngelHttpException.MethodNotAllowed();
2016-04-18 03:27:23 +00:00
}
/// Retrieves the desired resource.
Future<Object> read(id, [Map params]) {
throw new AngelHttpException.MethodNotAllowed();
2016-04-18 03:27:23 +00:00
}
/// Creates a resource.
Future<Object> create(Map data, [Map params]) {
throw new AngelHttpException.MethodNotAllowed();
2016-04-18 03:27:23 +00:00
}
/// Modifies a resource.
Future<Object> modify(id, Map data, [Map params]) {
throw new AngelHttpException.MethodNotAllowed();
}
/// Overwrites a resource.
2016-04-18 03:27:23 +00:00
Future<Object> update(id, Map data, [Map params]) {
throw new AngelHttpException.MethodNotAllowed();
2016-04-18 03:27:23 +00:00
}
/// Removes the given resource.
Future<Object> remove(id, [Map params]) {
throw new AngelHttpException.MethodNotAllowed();
2016-04-18 03:27:23 +00:00
}
Service() : super() {
get('/', (req, res) async => await this.index(req.query));
post('/', (req, res) async => await this.create(req.body));
2016-04-18 03:27:23 +00:00
get('/:id', (req, res) async =>
await this.read(req.params['id'], req.query));
2016-04-18 03:27:23 +00:00
patch('/:id', (req, res) async => await this.modify(
req.params['id'], req.body));
2016-04-18 03:27:23 +00:00
post('/:id', (req, res) async => await this.update(
req.params['id'], req.body));
2016-04-18 03:27:23 +00:00
delete('/:id', (req, res) async => await this.remove(req.params['id'], req.query));
}
2016-04-18 03:27:23 +00:00
}