fnx_rest 0.5.0

  • README.md
  • Installing
  • Versions
  • 13


Set of REST tools which work nicely with Angular2 Dart.

This is a plain old REST client, if you are looking for something more sophisticated, try streamy for instance.

fnx_rest is oriented to be developer and Angular friendly and is particularly useful when creating boring CRUD applications with many similar API calls.


RestClient root = HttpRestClient.root("/api/v1");        
RestResult response = await root.child("/users").get();
List users = response.data;

Angular support

You can define root REST client, add your API keys and other additional headers to it and inject this root client with Angular's dependency injection to your elements and/or services.

# Angular initialization
RestClient root = HttpRestClient.root("/api/v1");            
bootstrap(MyApp, [ provide(RestClient, useValue: root) ]);
# your component
class MyApp {
    RestClient restRoot;

# add custom headers, for example after user's signing in
restRoot.setHeader("Authorization", authKey);        

RestClient is hierarchical:

RestClient root = HttpRestClient.root("/api/v1");   //  /api/v1
RestClient users = root.child("/users");            //  /api/v1/users            
RestClient john = users.child("/123");              //  /api/v1/users/123

All children inherit configuration of their parents, but are allowed to override it.

Typically you would create a child of the root rest client in your component like this:

class UserManagement {
    RestClient users;
    UserManagement(RestClient root) {
        users = root.child("/users"); // endpoint /api/v1/users

Every instance of RestClient has bool working property, which indicates whether this client is currently processing a request/response or not. You can us it to indicate "working" state to the user:

<p *ngIf="john.working">Sending user data to server ...</p>

This property is recursively propagated to client's parents so you can indicate this "working" state on any level. Locally (for a form), or globally (for the whole app).

// update user     

Until the request is processed, john.working == true, users.working == true and root.working == true.

// read users
users.get( ... )

In this case john.working == false but users.working == true and root.working == true.

You can easily use this behaviour to disable a form and all it's buttons after submitting edited user data, but in the same time you can have universal global indicator of any HTTP communication (in your app status bar, for example).

HTTP methods

RestClient has following methods:

Future<RestResult> get({Map<String, String> headers}) ...
Future<RestResult> post(dynamic data, {Map<String, String> headers}) ...
Future<RestResult> put(dynamic data, {Map<String, String> headers}) ...
Future<RestResult> delete({Map<String, String> headers}) ...

Use optional parameter headers to specify custom ad-hoc headers you need in this call only. Headers will be merged with your RestClient default headers, it's parent's headers etc. up to the root RestClient.

Don't use this parameter to specify Content-Type or Accept headers, see below.


Each call returns Future<RestResult>. RestResult contains status (HTTP status, int) and data which are already converted to your desired type (see below) - Dart Map or Dart List by default.

Request/response serialization

By default, the root client is configured to produce and consume JSON and Dart Maps and Lists. You can easily customize this behaviour to accept or produce any binary data:

RestClient img = root.child("/images");        //  /api/v1/images     

Such data will be sent and received as List<int> or inject any custom text based serialization or deserialization you need:

typedef dynamic Serializer(dynamic payload);
typedef dynamic Deserializer(String payload);

client.accepts("text/csv", myCsvDeserializeFunction);
client.produces("text/csv", myCsvSerializeFunction);

This configuration is inherited by client's children.

Custom HTTP client

This client is mainly intended for client side, but you can use it on server side too, just provide custom HTTP client to the RestClient constructor.

 RestClient(HttpClient httpClient, RestClient parent, String url, {Map<String, String> headers});

For usage on the web client use convenient predefined client:

RestClient root = HttpRestClient.root("/api/v1");

Work in progress

Suggestions, pull requests and bugreports are more than welcome.



  • Initial version

1. Depend on it

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

  fnx_rest: "^0.5.0"

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:fnx_rest/fnx_rest.dart';
Version Uploaded Documentation Archive
0.5.0 Dec 7, 2016 failed Download fnx_rest 0.5.0 archive


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

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6


Describes how popular the package is relative to other packages. [more]
0 / 100
Code health derived from static analysis. [more]
18 / 100
Reflects how tidy and up-to-date the package is. [more]
40 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: unsure

Error(s) prevent platform classification:

Error(s) in lib/fnx_rest.dart: Target of URI doesn't exist: 'package:http/browser_client.dart'.


  • Fix platform conflicts.

    Error(s) prevent platform classification:

    Error(s) in lib/fnx_rest.dart: Target of URI doesn't exist: 'package:http/browser_client.dart'.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 20 errors 6 hints.

    Make sure that the imported libraries are not in conflict. Error(s) in lib/fnx_rest.dart: Target of URI doesn't exist: 'package:http/browser_client.dart'.

    Strong-mode analysis of lib/src/rest_client.dart failed with the following error:

    line: 4 col: 8
    Target of URI doesn't exist: 'package:http/src/response.dart'.

    Similar analysis of the following files failed:

    • lib/src/rest_listing.dart (hint)
  • The description is too short.

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

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    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 fnx_rest.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0
browser ^0.10.0 0.10.0+3
dart_to_js_script_rewriter ^1.0.1 1.0.3
logging ^0.11.3 0.11.3+1
Transitive dependencies
args 1.4.2
async 2.0.6
barback 0.15.2+15
charcode 1.1.1
collection 1.14.9
csslib 0.14.1
html 0.13.3
path 1.5.1
pool 1.3.4
source_span 1.4.0
stack_trace 1.9.2
utf 0.9.0+4
Dev dependencies
mockito ^1.0.1
test >=0.12.0 <0.13.0