pip_clients_roles 1.1.0 copy "pip_clients_roles: ^1.1.0" to clipboard
pip_clients_roles: ^1.1.0 copied to clipboard

Clients for User roles microservice for Pip.Services in Dart

example/README.md

Examples for Roles Microservice #

This is a user roles microservice from Pip.Services library. It provides basic role-based authorization mechanism for users.

Define configuration parameters that match the configuration of the microservice's external API

// Service/Client configuration
var httpConfig = ConfigParams.fromTuples(
	"connection.protocol", "http",
	"connection.host", "localhost",
	"connection.port", 8080
);

Instantiate the client and open connection to the microservice

// Create the client instance
var client = RolesHttpClientV1(config);

// Configure the client
client.configure(httpConfig);

// Connect to the microservice
try{
  await client.open(null)
}catch() {
  // Error handling...
}       
// Work with the microservice
// ...

Now the client is ready to perform operations

final ROLES = ['Role 1', 'Role 2', 'Role 3'];

    // Set the roles
    try {
      var role = await client.setRoles('123', '1', ROLES);
      // Do something with the returned roles...
    } catch(err) {
      // Error handling...     
    }
// Get the roles by id
try {
var role = await client.getRolesById(
    null,
    '1');
    // Do something with roles...

    } catch(err) { // Error handling}
// Grant user a role
try {
var role = await client.grantRoles(
    null,
    '1',
    ['admin']);
    // Do something with roles...

    } catch(err) { // Error handling}

// Authorize user
try {
var role = await client.authorize(
    null,
    '1',
    ['admin']);
    // Do something with bool value(authorized or not authorized) ...

    } catch(err) { // Error handling}    

In the help for each class there is a general example of its use. Also one of the quality sources are the source code for the tests.