2016-04-18 03:27:23 +00:00
|
|
|
part of angel_framework.http;
|
|
|
|
|
2016-06-19 05:02:41 +00:00
|
|
|
class Providers {
|
|
|
|
final String via;
|
|
|
|
|
|
|
|
const Providers._base(String this.via);
|
|
|
|
|
|
|
|
static final Providers SERVER = const Providers._base('server_side');
|
|
|
|
static final Providers REST = const Providers._base('rest');
|
|
|
|
static final Providers WEBSOCKET = const Providers._base('websocket');
|
|
|
|
}
|
|
|
|
|
2016-04-18 03:27:23 +00:00
|
|
|
/// A data store exposed to the Internet.
|
|
|
|
class Service extends Routable {
|
Angel.secure, fallback routes, 404, app.addRoute, app.all, services are a go (just missing params, i.e. $sort?), now have service.app, app.before, app.after, angel.configure now uses futures, errors are implemented
2016-04-29 00:01:58 +00:00
|
|
|
/// The [Angel] app powering this service.
|
|
|
|
Angel app;
|
2016-04-18 03:27:23 +00:00
|
|
|
|
|
|
|
/// Retrieves all resources.
|
|
|
|
Future<List> index([Map params]) {
|
Angel.secure, fallback routes, 404, app.addRoute, app.all, services are a go (just missing params, i.e. $sort?), now have service.app, app.before, app.after, angel.configure now uses futures, errors are implemented
2016-04-29 00:01:58 +00:00
|
|
|
throw new AngelHttpException.MethodNotAllowed();
|
2016-04-18 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Retrieves the desired resource.
|
2016-05-02 22:28:14 +00:00
|
|
|
Future read(id, [Map params]) {
|
Angel.secure, fallback routes, 404, app.addRoute, app.all, services are a go (just missing params, i.e. $sort?), now have service.app, app.before, app.after, angel.configure now uses futures, errors are implemented
2016-04-29 00:01:58 +00:00
|
|
|
throw new AngelHttpException.MethodNotAllowed();
|
2016-04-18 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a resource.
|
2016-06-19 05:02:41 +00:00
|
|
|
Future create(data, [Map params]) {
|
Angel.secure, fallback routes, 404, app.addRoute, app.all, services are a go (just missing params, i.e. $sort?), now have service.app, app.before, app.after, angel.configure now uses futures, errors are implemented
2016-04-29 00:01:58 +00:00
|
|
|
throw new AngelHttpException.MethodNotAllowed();
|
2016-04-18 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Modifies a resource.
|
2016-06-19 05:02:41 +00:00
|
|
|
Future modify(id, data, [Map params]) {
|
Angel.secure, fallback routes, 404, app.addRoute, app.all, services are a go (just missing params, i.e. $sort?), now have service.app, app.before, app.after, angel.configure now uses futures, errors are implemented
2016-04-29 00:01:58 +00:00
|
|
|
throw new AngelHttpException.MethodNotAllowed();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Overwrites a resource.
|
2016-06-19 05:02:41 +00:00
|
|
|
Future update(id, data, [Map params]) {
|
Angel.secure, fallback routes, 404, app.addRoute, app.all, services are a go (just missing params, i.e. $sort?), now have service.app, app.before, app.after, angel.configure now uses futures, errors are implemented
2016-04-29 00:01:58 +00:00
|
|
|
throw new AngelHttpException.MethodNotAllowed();
|
2016-04-18 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Removes the given resource.
|
2016-05-02 22:28:14 +00:00
|
|
|
Future remove(id, [Map params]) {
|
Angel.secure, fallback routes, 404, app.addRoute, app.all, services are a go (just missing params, i.e. $sort?), now have service.app, app.before, app.after, angel.configure now uses futures, errors are implemented
2016-04-29 00:01:58 +00:00
|
|
|
throw new AngelHttpException.MethodNotAllowed();
|
2016-04-18 03:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Service() : super() {
|
2016-06-19 05:02:41 +00:00
|
|
|
Map restProvider = {'provider': Providers.REST};
|
|
|
|
|
|
|
|
get('/', (req, res) async => await this.index(
|
|
|
|
mergeMap([req.query, restProvider])));
|
Angel.secure, fallback routes, 404, app.addRoute, app.all, services are a go (just missing params, i.e. $sort?), now have service.app, app.before, app.after, angel.configure now uses futures, errors are implemented
2016-04-29 00:01:58 +00:00
|
|
|
|
2016-06-19 05:02:41 +00:00
|
|
|
post('/', (req, res) async => await this.create(
|
|
|
|
mergeMap([req.body, restProvider])));
|
Angel.secure, fallback routes, 404, app.addRoute, app.all, services are a go (just missing params, i.e. $sort?), now have service.app, app.before, app.after, angel.configure now uses futures, errors are implemented
2016-04-29 00:01:58 +00:00
|
|
|
|
2016-04-18 03:27:23 +00:00
|
|
|
get('/:id', (req, res) async =>
|
2016-06-19 05:02:41 +00:00
|
|
|
await this.read(req.params['id'], mergeMap([req.query, restProvider])));
|
2016-04-18 03:27:23 +00:00
|
|
|
|
Angel.secure, fallback routes, 404, app.addRoute, app.all, services are a go (just missing params, i.e. $sort?), now have service.app, app.before, app.after, angel.configure now uses futures, errors are implemented
2016-04-29 00:01:58 +00:00
|
|
|
patch('/:id', (req, res) async => await this.modify(
|
2016-06-19 05:02:41 +00:00
|
|
|
req.params['id'], mergeMap([req.body, restProvider])));
|
2016-04-18 03:27:23 +00:00
|
|
|
|
Angel.secure, fallback routes, 404, app.addRoute, app.all, services are a go (just missing params, i.e. $sort?), now have service.app, app.before, app.after, angel.configure now uses futures, errors are implemented
2016-04-29 00:01:58 +00:00
|
|
|
post('/:id', (req, res) async => await this.update(
|
2016-06-19 05:02:41 +00:00
|
|
|
req.params['id'], mergeMap([req.body, restProvider])));
|
2016-04-18 03:27:23 +00:00
|
|
|
|
2016-06-19 05:02:41 +00:00
|
|
|
delete('/:id', (req, res) async => await this.remove(
|
|
|
|
req.params['id'], mergeMap([req.query, restProvider])));
|
Angel.secure, fallback routes, 404, app.addRoute, app.all, services are a go (just missing params, i.e. $sort?), now have service.app, app.before, app.after, angel.configure now uses futures, errors are implemented
2016-04-29 00:01:58 +00:00
|
|
|
}
|
2016-04-18 03:27:23 +00:00
|
|
|
}
|