platform/packages/client
2024-05-22 00:26:09 +08:00
..
example Fixed Basic Auth issue 2023-06-08 00:42:34 +08:00
lib Upgraded lints to 3.0.0 2023-12-24 09:52:57 +08:00
test Published 8.0.0 2023-06-10 12:10:21 +08:00
web Publish client 2021-05-15 14:53:03 +08:00
.babelrc Add 'packages/client/' from commit '180edbc46a556f6d572c3b4ade4b396a31a1bc42' 2020-02-15 18:28:35 -05:00
.gitignore Updated pubspec 2022-08-29 01:51:56 +08:00
.npmignore Add 'packages/client/' from commit '180edbc46a556f6d572c3b4ade4b396a31a1bc42' 2020-02-15 18:28:35 -05:00
.pubignore Cleanup unused 2022-04-23 16:51:55 +08:00
analysis_options.yaml Updated linter to package:lints 2021-09-25 14:32:32 +08:00
AUTHORS.md Publish angle3_json_god 2021-05-14 20:24:45 +08:00
build.yaml Add 'packages/client/' from commit '180edbc46a556f6d572c3b4ade4b396a31a1bc42' 2020-02-15 18:28:35 -05:00
CHANGELOG.md Updated repository links 2023-12-25 11:45:10 +08:00
dart_test.yaml Add 'packages/client/' from commit '180edbc46a556f6d572c3b4ade4b396a31a1bc42' 2020-02-15 18:28:35 -05:00
LICENSE Updated linter to package:lints 2021-09-25 14:32:32 +08:00
melos_angel3_client.iml Added melos 2022-03-19 09:37:28 +08:00
package.json Add 'packages/client/' from commit '180edbc46a556f6d572c3b4ade4b396a31a1bc42' 2020-02-15 18:28:35 -05:00
pubspec.yaml Updated lints 2024-05-22 00:26:09 +08:00
README.md Updated repository links 2023-12-25 11:45:10 +08:00

Angel3 Client

Pub Version (including pre-releases) Null Safety Gitter License

A browser, mobile and command line based client that supports querying Angel3 backend.

Usage

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

main() async {
  Angel app = 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 package:belatuk_json_serializer. 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 = ServiceList(app.service('api/todos'));
  
  return StreamBuilder(
    stream: list.onChange,
    builder: _yourBuildFunction,
  );
}