cubarestapi 0.0.3 copy "cubarestapi: ^0.0.3" to clipboard
cubarestapi: ^0.0.3 copied to clipboard

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

1
likes
5
pub points
0%
popularity

Publisher

unverified uploader

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

Homepage

License

unknown (LICENSE)

Dependencies

dio, hive, oauth2

More

Packages that depend on cubarestapi