cubarestapi 0.0.3

Flutter Android iOS web

A new flutter plugin for simplier interaction with Cuba's REST API.

cubarestapi #

A lightweight package for using Cuba`s REST-API.

! Still raw (development in progress)

Get started #

Add dependency #

dependencies:
  cubarestapi: ^0.0.3

Initialize Hive #

Initialize Hive before using cubarestapi by calling asynchronous method:

(if you use it in flutter hive_flutter)

Hive.initFlutter(); // `package:hive_flutter/hive_flutter.dart`

Initialize CubaRestApi variables #

Initialize baseUrl, identifier, and secret of CubaRestApi class before using it:

CubaRestApi.baseUrl = 'your url';       // http://localhost:8080/app by default
CubaRestApi.identifier = 'your client'; // client by default
CubaRestApi.secret = 'your secret';     // secret by default

Example #

Very simple to use:

// ...
// authorization using Cuba's /rest/v2/oauth/token
child: OutlineButton(
    child: const Text('Login');
    onPressed: () async {
      oauth2.Client = await CubaRestApi.getAuthToken(usernameController.text, passwordController.text);
      // move to another screen or update ui
    }
),
// ...
// ...
// get some entities
List<Person> items = [];
void getPersons({String view, int limit, int offset, String sort}) {
    CubaRestApi.getEntities('testProject_Person',
                view: view, limit: limit, offset: offset, sort: sort)
            .then((result) {
        items.clear();
        (result as List).forEach((p) => items.add(Person.fromMap(p as Map)));
    }).catchError((e) {
        // add error to some stream controller to show flushbar with error or whatever
    });
}
// ...

This opensource project authorized by Sberbank Technology, and the license is Apache 2.0

Author - Roman Sotnichenko

0
likes
85
pub points
7%
popularity

A new flutter plugin for simplier interaction with Cuba's REST API.

Homepage

Documentation

API reference

Uploader

geep2795@gmail.com

License

Apache 2.0 (LICENSE)

Dependencies

dio, hive, oauth2

More

Packages that depend on cubarestapi