A new Flutter package for integration with CUBA Platform based backend.
- Authorization via the Rest Api using your username and password
- Storing and reusing Access Token
- Compliance with the CUBA documentation for the REST API. (at the moment partial)
in your pubspec.yaml add dependency
dependencies:
flutter:
sdk: flutter
kinfolk: ^0.0.4
then run. packages get
/// initialize service
Kinfolk kinfolk = Kinfolk();
/// setting server url and security keys (identifier,secter)
kinfolk.initializeBaseVariables("http://localhost:8080/test", "client", "secret", Directory.current.path);
/// getting client (service with Access Token) in first time with login,password
oauth2.Client client = await kinfolk.getToken("admin", "admin");
/// getting single model
/// test_SomeService - service name
/// getToDoList - method name
/// Types - enum
/// formMap - function converting Map<String, dynamic> map to your Model
ToDoList model =
Kinfolk.getSingleModelRest(
serviceName: "test_SomeService",
methodName: "getToDoList",
type: Types.services,
fromMap: (Map<String, dynamic> val)=> ToDoList.fromMap(val));
String body = """
{
"monday":"work",
"sunday":"relax"
}
""";
/// getting single model with request body
/// test_SomeService - service name
/// getToDoList - method name
/// Types - enum
/// body - request body
/// formMap - function converting Map<String, dynamic> map to your Model
ToDoList model =
Kinfolk.getSingleModelRest(
serviceName: "test_SomeService",
methodName: "getToDoList",
type: Types.services,
body: body,
fromMap: (Map<String, dynamic> val)=> ToDoList.fromMap(val));
/// getting models list
/// test_SomeService - service name
/// getToDoList - method name
/// Types - enum
/// formMap - function converting Map<String, dynamic> map to your Model
List<dynamic> modelsList =
Kinfolk.getListModelRest(
serviceName: "test_SomeService",
methodName: "getToDoList",
type: Types.services,
fromMap: (Map<String, dynamic> val)=> ToDoList.fromMap(val));
/// getting models list with request body
/// test_SomeService - service name
/// getToDoList - method name
/// Types - enum
/// body - request body
/// formMap - function converting Map<String, dynamic> map to your Model
List<dynamic> modelsList =
Kinfolk.getListModelRest(
serviceName: "test_SomeService",
methodName: "getToDoList",
type: Types.services,
body: body,
fromMap: (Map<String, dynamic> val)=> ToDoList.fromMap(val));
/// Manual rest service usage. only if you want full control
/// url to service
String url =
Kinfolk.createRestUrl("test_SomeService", "setToDoList", Types.services);
/// request body
String body = """
{
"monday":"work",
"sunday":"relax"
}
""";
/// getting client from saved Access Token
oauth2.Client client = await Kinfolk.getClient();
// getting response from server. POST method
var response =
await client.post(url, body: body, headers: Kinfolk.appJsonHeader);
/// printing body of response
print("${response.body}");
Yerassyl Maikhanov - Enterprise Applications Developer. My Linkedin