The Protevus Platform: Unified Full-Stack Development https://protevus.com
Find a file
2019-01-05 21:10:21 -05:00
example 2.0.0 2019-01-05 21:08:31 -05:00
lib 2.0.0 2019-01-05 21:08:31 -05:00
test 2.0.0 2019-01-05 21:08:31 -05:00
web 2.0.0 2019-01-05 21:08:31 -05:00
.babelrc More 2016-12-13 11:35:35 -05:00
.gitignore 2.0.0-alpha 2018-08-26 18:41:01 -04:00
.npmignore More 2016-12-13 11:35:35 -05:00
.travis.yml Update .travis.yml 2018-07-09 10:46:54 -04:00
analysis_options.yaml 2.0.0 2019-01-05 21:08:31 -05:00
build.yaml More DDC fixes 2018-06-22 20:18:38 -04:00
CHANGELOG.md 2.0.0 2019-01-05 21:08:31 -05:00
dart_test.yaml 1.0.4 2017-03-28 21:52:19 -04:00
LICENSE Initial commit 2016-06-23 15:13:52 -04:00
package.json More 2016-12-13 11:35:35 -05:00
pubspec.yaml pubspec description 2019-01-05 21:10:21 -05:00
README.md Added ServiceList 2017-12-10 00:13:31 -05:00

angel_client

Pub build status

Client library for the Angel framework. This library provides virtually the same API as an Angel server. The client can run in the browser, in Flutter, or on the command-line. In addition, the client supports angel_auth authentication.

Usage

// Choose one or the other, depending on platform
import 'package:angel_client/io.dart';
import 'package:angel_client/browser.dart';
import 'package:angel_client/flutter.dart';

main() async {
  Angel app = new Rest("http://localhost:3000");
}

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!).

foo() async {
  Service Todos = app.service("todos");
  List<Map> todos = await Todos.index();

  print(todos.length);
}

The CLI client also supports reflection via json_god. There is no need to work with Maps; you can use the same class on the client and the server.

class Todo extends Model {
  String text;

  Todo({String this.text});
}

bar() async {
  // By the next release, this will just be:
  // app.service<Todo>("todos")
  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 remove.

Authentication

Local auth:

var auth = await app.authenticate(type: 'local', credentials: {username: ..., password: ...});
print(auth.token);
print(auth.data); // User object

Revive an existing jwt:

Future<AngelAuthResult> reviveJwt(String jwt) {
  return app.authenticate(credentials: {'token': jwt});
}

Via Popup:

app.authenticateViaPopup('/auth/google').listen((jwt) {
  // Do something with the JWT
});

Resume a session from localStorage (browser only):

// Automatically checks for JSON-encoded 'token' in localStorage,
// and tries to revive it
await app.authenticate();

Logout:

await app.logout();

Live Updates

Oftentimes, you will want to update a collection based on updates from a service. Use ServiceList for this case:

build(BuildContext context) async {
  var list = new ServiceList(app.service('api/todos'));
  
  return new StreamBuilder(
    stream: list.onChange,
    builder: _yourBuildFunction,
  );
}