angel_client 1.2.0+1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 40

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,
  );
}

1.2.0+1

  • Removed a type annotation in authenticateViaPopup to prevent breaking with DDC.

1.2.0

  • ServiceList now uses Equality from package:collection to compare items.
  • Services will now add service errors to corresponding streams if there is a listener.

1.1.0+3

  • ServiceList no longer ignores empty index events.

1.1.0+2

  • Updated ServiceList to also fire on index.

1.1.0+1

  • Added ServiceList.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  angel_client: ^1.2.0+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:angel_client/angel_client.dart';
  
Version Uploaded Documentation Archive
1.2.0+1 Dec 27, 2017 Go to the documentation of angel_client 1.2.0+1 Download angel_client 1.2.0+1 archive
1.2.0 Dec 21, 2017 Go to the documentation of angel_client 1.2.0 Download angel_client 1.2.0 archive
1.1.0+3 Dec 13, 2017 Go to the documentation of angel_client 1.1.0+3 Download angel_client 1.1.0+3 archive
1.1.0+2 Dec 13, 2017 Go to the documentation of angel_client 1.1.0+2 Download angel_client 1.1.0+2 archive
1.1.0+1 Dec 10, 2017 Go to the documentation of angel_client 1.1.0+1 Download angel_client 1.1.0+1 archive
1.1.0 Dec 7, 2017 Go to the documentation of angel_client 1.1.0 Download angel_client 1.1.0 archive
1.0.7 Jun 30, 2017 Go to the documentation of angel_client 1.0.7 Download angel_client 1.0.7 archive
1.0.6 Jun 3, 2017 Go to the documentation of angel_client 1.0.6 Download angel_client 1.0.6 archive
1.0.5 Jun 3, 2017 Go to the documentation of angel_client 1.0.5 Download angel_client 1.0.5 archive
1.0.4 Mar 29, 2017 Go to the documentation of angel_client 1.0.4 Download angel_client 1.0.4 archive

All 42 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
59
Health:
Code health derived from static analysis. [more]
1
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
50
Overall:
Weighted score of the above. [more]
40
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6

Platforms

Detected platforms: unsure

Low code quality prevents platform classification.

Health issues and suggestions

Fix lib/base_angel_client.dart. (-95.82 points)

Analysis of lib/base_angel_client.dart failed with 11 errors, 2 hints, including:

line 38 col 18: Undefined name 'JSON'.

line 98 col 22: Undefined name 'JSON'.

line 122 col 19: Undefined name 'JSON'.

line 132 col 22: Undefined name 'JSON'.

line 292 col 12: Undefined name 'JSON'.

Fix lib/browser.dart. (-76.51 points)

Analysis of lib/browser.dart failed with 5 errors, 2 hints, including:

line 32 col 36: Undefined name 'JSON'.

line 34 col 40: Undefined name 'JSON'.

line 35 col 39: Undefined name 'JSON'.

line 44 col 38: Undefined name 'JSON'.

line 45 col 37: Undefined name 'JSON'.

Fix lib/angel_client.dart. (-25.38 points)

Analysis of lib/angel_client.dart failed with 1 error, 1 hint:

line 86 col 35: Undefined name 'JSON'.

line 5 col 8: Unused import: 'dart:convert'.

Fix additional 3 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/auth_types.dart (Run dartfmt to format lib/auth_types.dart.)
  • lib/flutter.dart (Run dartfmt to format lib/flutter.dart.)
  • lib/io.dart (Run dartfmt to format lib/io.dart.)

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Low code quality prevents platform classification.

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use angel_client.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.21.0
angel_http_exception ^1.0.0 1.0.0+3
collection ^1.0.0 1.14.11
http >=0.11.3 <0.12.0 0.11.3+17 0.12.0
json_god >=2.0.0-beta <3.0.0 2.0.0-beta+3
merge_map >=1.0.0 <2.0.0 1.0.1
Transitive dependencies
async 2.0.8
charcode 1.1.2
dart2_constant 1.0.2+dart2
http_parser 3.1.3
logging 0.11.3+2
meta 1.1.6
path 1.6.2
source_span 1.4.1
string_scanner 1.0.4
typed_data 1.1.6
Dev dependencies
angel_framework ^1.1.0-alpha
angel_model ^1.0.0
mock_request ^1.0.0
test >=0.12.13 <0.13.0