part of angel_framework.http; /// A data store exposed to the Internet. class Service extends Routable { /// Retrieves all resources. Future index([Map params]) { throw new MethodNotAllowedError('find'); } /// Retrieves the desired resource. Future read(id, [Map params]) { throw new MethodNotAllowedError('get'); } /// Creates a resource. Future create(Map data, [Map params]) { throw new MethodNotAllowedError('create'); } /// Modifies a resource. Future update(id, Map data, [Map params]) { throw new MethodNotAllowedError('update'); } /// Removes the given resource. Future remove(id, [Map params]) { throw new MethodNotAllowedError('remove'); } Service() : super() { get('/', (req, res) async => res.json(await this.index(req.query))); get('/:id', (req, res) async => res.json(await this.read(req.params['id'], req.query))); post('/', (req, res) async => res.json(await this.create(req.body))); post('/:id', (req, res) async => res.json(await this.update(req.params['id'], req.body))); delete('/:id', (req, res) async => res.json(await this.remove(req.params['id'], req.body))); } } /// Thrown when an unimplemented method is called. class MethodNotAllowedError extends Error { /// The action that threw the error. /// /// Ex. 'get', 'remove' String action; /// A description of this error. String get error => 'This service does not support the "$action" action.'; MethodNotAllowedError(String this.action); }