플랫폼에 관계없이 작동하는 Dart/Flutter 패키지로, Firebase Realtime Database를 위한 REST 기반 래퍼를 제공합니다. HTTP 요청을 사용하여 Firebase 데이터베이스와 원활하게 상호작용할 수 있으며, 네이티브 Firebase SDK가 사용 불가능한 환경에서도 적합합니다. 이 패키지는 저수준 REST 호출을 직관적인 Dart 메서드로 추상화하여 데이터 읽기, 쓰기 및 풀링을 통한 실시간 업데이트를 지원합니다. 단순성과 다중 플랫폼 호환성을 고려해 설계되어, 플랫폼별 플러그인에 의존하지 않고 Firebase 통합이 필요한 앱에 이상적입니다.
사용 사례
크로스 플랫폼 Firebase 데이터베이스 접근
서버 측 플러터 애플리케이션
웹 및 데스크톱 앱 통합
오프라인 우선 시나리오 및 수동 동기화
경량 Firebase 상호작용
주요 기능
REST API 기반 통신
플랫폼에 관계없는 설계
간단한 CRUD 작업
폴링 기반 실시간 업데이트
내장 SDK 종속성 없음
적합한 대상
웹 또는 데스크톱을 대상으로 하는 개발자
네이티브 Firebase 플러그인을 피하는 프로젝트
Flutter를 사용한 백엔드 서비스
경량 Firebase 접근을 필요로 하는 앱
고려 사항
실시간 업데이트 수동 처리
네이티브 SDK보다 높은 지연
REST 호환 기능에 제한됨
내장된 오프라인 지속성 없음
수동 오류 처리 및 재시도 로직이 필요합니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
firebase_database_rest
A platform independent Dart/Flutter Wrapper for the Firebase Realtime Database API based on REST
Features
Pure Dart-based implementation
works on all platforms supported by dart
Uses the official REST-API endpoints
Provides high-level classes to manage database access
Supports Model-Binding via Generics and converter functions
Full support of all Realtime database features:
Supports CRUD
Supports Queries (filtering, sorting)
Supports realtime server updates (streaming)
Supports ETags
Provides a Transaction class to wrap ETag-Logic into safe transactions
Provides timestamp class for server set timestamps
Proivides low-level REST classes for direct API access (import firebase_database_rest/rest.dart)
Fully integrated with firebase_auth_rest - including automatic auth token refreshes
Installation
Simply add firebase_database_rest to your pubspec.yaml and run pub get (or flutter pub get).
Usage
The libraries primary class is the FirebaseStore. It is a high-level class that allows access to a certain part of the realtime database using Model binding.
With this store, you specify a subpatch and can then perform various operations on elements below that path (list key, create, read, write or delete them, ...).
This class also provides the APIs for streaming changes and transactions. Typically, your application would use multiple stores, one for each dataclass you plan
to store at a certain path.
The second important class is the FirebaseDatabase. It serves as the toplevel class, parent to all stores and manages the database connection itself, including
the management of the associated FirebaseAccount (from firebase_auth_rest) and background ressources
(like the REST-API interface).
The following code is a simple example, which can be found in full length, including errorhandling, at https://pub.dev/packages/firebase_database_rest/example. It loggs into firebase as anonymous user, starts streaming changes and then does some db operations.
// The data class that is stored in firebase
class ExampleModel {
final int id;
final String data;
const ExampleModel(this.id, this.data);
// ...
}
// obtain a firebase account, using firebase_auth_rest
final account = // ...
// create a database reference from that account
final database = FirebaseDatabase(
account: account,
database: 'my-firebase-realtime-database-name,
basePath: 'application/${account.localId}/example',
);
// create typed store. In this example, a callback store is used, but you can
// also just extend FirebaseStore
final store = database.createRootStore<ExampleModel>(
onDataFromJson: (dynamic json) => ExampleModel.fromJson(json),
onDataToJson: (data) => data.toJson(),
onPatchData: (data, updatedFields) => data.patch(updatedFields),
);
// add a stream listener that reports database changes in realtime
sub = (await store.streamAll()).listen((e) => print('Stream update: $e'));
// add some data to the store
await store.create(const ExampleModel(1, 'A'));
// get all data in store
print('All data: ${await store.all()}');
// cleanup: stop streaming and dispose of the database
await sub.cancel();
await database.dispose();
Documentation
The documentation is available at https://pub.dev/documentation/firebase_database_rest/latest/.
A full example can be found at https://pub.dev/packages/firebase_database_rest/example.