api_rest_flutter_web 3.0.0 copy "api_rest_flutter_web: ^3.0.0" to clipboard
api_rest_flutter_web: ^3.0.0 copied to clipboard

Platformweb

Flutter package for managing data operations with cloud backends. Provides a unified API layer for CRUD operations, data validation, schema management, and query building. Web-only support.

api_rest_flutter_web #

A Flutter package for managing data operations with cloud backends. Provides a unified API layer for CRUD operations, data validation, schema management, and query building.

Web-only support.

Features #

  • CRUD operations with cloud backends (MongoDB-based)
  • Schema-driven data validation
  • Query building with MongoDB syntax ($and, $or, $regex)
  • Automatic change tracking (only modified fields are sent)
  • Foreign key resolution with dynamic values
  • Pagination support
  • Backend function execution during save/update

Installation #

Add this to your pubspec.yaml:

dependencies:
  api_rest_flutter_web: ^2.0.0

Usage #

Initialization #

import 'package:api_rest_flutter_web/api_rest.dart';

// Initialize the ApiRest singleton
final apiRest = ApiRest(
  cloudDb: yourCloudDbInstance,
  modeToWork: ModeToWork.online,
  gestorData: yourGestorDataInstance,
  coleccionFuncionesBackend: 'funcionesBackend',
  enableDebugLogs: true,
);

await apiRest.init();

Read a record by ID #

final consulta = '{"idColeccion": "$idColeccion"}';
final response = await apiRest.leeById(
  coleccion: 'ciudadano',
  consulta: consulta,
  argsLocalBD: [['idServer'], ['='], [idColeccion]],
);

if (response.containsKey(EnvironmentApiRest.dataOk)) {
  final data = response[EnvironmentApiRest.data];
}

Query multiple records #

final consulta = '{"data.idProvincia": "$idProvincia"}';
final response = await apiRest.obtener(
  coleccion: 'localidad',
  consulta: consulta,
  argsLocalBD: [['idProvincia'], ['='], [idProvincia]],
  limit: '25',
  skip: '0',
);

if (response.containsKey(EnvironmentApiRest.dataOk)) {
  final items = response[EnvironmentApiRest.data];
  final totalItems = response[EnvironmentApiRest.totalItems];
}

Save a new record #

final ciudadano = ColeccionObjBox()
  ..coleccion = 'ciudadano'
  ..data = jsonEncode({
    'nombre': 'Juan',
    'apellido': 'Perez',
    'email': 'juanperez@gmail.com',
  });

final response = await apiRest.guardar(
  data: ciudadano,
  versionData: '1',
);

if (response.containsKey(EnvironmentApiRest.dataOk)) {
  final savedRecord = response[EnvironmentApiRest.data];
}

Update a record #

final response = await apiRest.actualizar(
  data: existingRecord,
  versionData: '1',
);

if (response.containsKey(EnvironmentApiRest.dataOk)) {
  final updatedRecord = response[EnvironmentApiRest.data];
}

Change record state #

final response = await apiRest.cambiaEstado(
  coleccion: 'ciudadano',
  id: idServer,
  estado: 'A', // Active
);

Data Validation #

final utilsData = UtilsDataApiRest(apiRest: apiRest);

final result = await utilsData.validaDataInMap(
  esquema: schemaMap,
  mapaActualizado: dataMap,
);

if (result.containsKey(EnvironmentApiRest.dataOk)) {
  // Validation passed
} else {
  final error = result[EnvironmentApiRest.error];
}

Response Format #

All API methods return Map<String, dynamic> with standard keys:

Success:

{
  EnvironmentApiRest.dataOk: 'OK',
  EnvironmentApiRest.data: <result>,
  EnvironmentApiRest.dataAtomica: true/false, // for atomic operations
}

Error:

{
  EnvironmentApiRest.dataNOk: 'NOK',
  EnvironmentApiRest.error: <message>,
}

Schema Types #

Supported field types:

  • string, number, boolean
  • array, arrayObjects, object
  • jsonString, autoGenerate

Supported data types for validation:

  • url, entero, decimal, correo
  • fecha, fechaHora, cuit, coleccion

Requirements #

  • Flutter >= 3.0.0
  • Dart SDK >= 3.1.0
  • Web platform only

License #

MIT License - see LICENSE file for details.

0
likes
145
points
364
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter package for managing data operations with cloud backends. Provides a unified API layer for CRUD operations, data validation, schema management, and query building. Web-only support.

Topics

#api #rest #cloud #crud #mongodb

Documentation

API reference

License

MIT (license)

Dependencies

collection, flutter, flutter_data_cloud_provider, flutter_data_shp_provider, flutter_http_provider, flutter_models_provider, flutter_security_provider, flutter_utils_providers, intl

More

Packages that depend on api_rest_flutter_web