platform/lib/angel_client.dart

61 lines
1.4 KiB
Dart
Raw Normal View History

2016-06-24 00:25:11 +00:00
/// Client library for the Angel framework.
library angel_client;
import 'dart:async';
2016-11-28 03:28:41 +00:00
import 'auth_types.dart' as auth_types;
2016-06-24 19:02:35 +00:00
2016-06-24 21:06:57 +00:00
/// A function that configures an [Angel] client in some way.
typedef Future AngelConfigurer(Angel app);
2016-06-24 19:02:35 +00:00
/// Represents an Angel server that we are querying.
abstract class Angel {
String basePath;
Angel(String this.basePath);
2016-06-24 21:06:57 +00:00
2016-11-29 00:42:02 +00:00
Future<AngelAuthResult> authenticate(
2016-12-03 18:21:44 +00:00
{String type,
2016-11-29 00:42:02 +00:00
credentials,
String authEndpoint: '/auth',
String reviveEndpoint: '/auth/token'});
2016-11-28 03:28:41 +00:00
2016-06-24 21:06:57 +00:00
/// Applies an [AngelConfigurer] to this instance.
Future configure(AngelConfigurer configurer) async {
await configurer(this);
}
Service service(Pattern path, {Type type});
2016-06-24 19:02:35 +00:00
}
2016-06-24 00:25:11 +00:00
2016-11-28 03:28:41 +00:00
/// Represents the result of authentication with an Angel server.
abstract class AngelAuthResult {
Map<String, dynamic> get data;
String get token;
2016-12-03 18:21:44 +00:00
Map<String, dynamic> toJson();
2016-11-28 03:28:41 +00:00
}
2016-06-24 00:25:11 +00:00
/// Queries a service on an Angel server, with the same API.
abstract class Service {
2016-06-24 21:06:57 +00:00
/// The Angel instance powering this service.
2016-11-28 03:28:41 +00:00
Angel get app;
2016-06-24 21:06:57 +00:00
2016-06-24 00:25:11 +00:00
/// Retrieves all resources.
Future<List> index([Map params]);
/// Retrieves the desired resource.
Future read(id, [Map params]);
/// Creates a resource.
Future create(data, [Map params]);
/// Modifies a resource.
Future modify(id, data, [Map params]);
/// Overwrites a resource.
Future update(id, data, [Map params]);
/// Removes the given resource.
Future remove(id, [Map params]);
2016-09-03 12:02:32 +00:00
}