platform/README.md

58 lines
1.4 KiB
Markdown
Raw Normal View History

2016-06-23 19:13:52 +00:00
# angel_client
2016-12-09 00:24:07 +00:00
2016-12-13 16:35:35 +00:00
[![pub 1.0.0-dev+21](https://img.shields.io/badge/pub-1.0.0--dev+21-red.svg)](https://pub.dartlang.org/packages/angel_client)
2016-12-09 00:24:07 +00:00
![build status](https://travis-ci.org/angel-dart/client.svg)
2016-06-23 19:13:52 +00:00
Client library for the Angel framework.
2016-06-24 21:06:57 +00:00
# Isomorphic
2016-06-25 18:37:49 +00:00
The REST client can run in the browser or on the command-line.
2016-06-24 21:06:57 +00:00
# Usage
This library provides the same API as an Angel server.
```dart
2016-06-25 18:37:49 +00:00
// Choose one or the other, depending on platform
import 'package:angel_client/cli.dart';
import 'package:angel_client/browser.dart';
2016-06-24 21:06:57 +00:00
main() async {
Angel app = new Rest("http://localhost:3000", new BrowserClient());
}
```
You can call `service` to receive an instance of `Service`, which acts as a client to a
service on the server at the given path (say that five times fast!).
```dart
foo() async {
Service Todos = app.service("todos");
List<Map> todos = await Todos.index();
print(todos.length);
}
```
2016-09-03 12:04:00 +00:00
The CLI client also supports reflection via `json_god`. There is no need to work with Maps;
2016-06-24 21:06:57 +00:00
you can use the same class on the client and the server.
```dart
class Todo extends Model {
String text;
Todo({String this.text});
}
bar() async {
2016-12-10 14:45:22 +00:00
// By the next release, this will just be:
// app.service<Todo>("todos")
2016-06-24 21:06:57 +00:00
Service Todos = app.service("todos", type: Todo);
List<Todo> todos = await Todos.index();
print(todos.length);
}
```
Just like on the server, services support `index`, `read`, `create`, `modify`, `update` and
2016-09-03 12:04:00 +00:00
`remove`.