Firebase REST Client for Node 🔥
- We make requests with the HTTP Fetch API via node-fetch
- You can bring your own Promise library by calling
FirebaseREST.setPromise(Promise)
Installation
npm install firebase-rest --save
Usage
// Don't forget `.default` at the end! (We use ES6 modules from the future.)const FirebaseREST = default;
Instantiate a either the FirebaseREST.JSONClient
or the FirebaseREST.Client
, and start making calls. What's the difference?
JSONClient
promises an HTTP fetch response where the#body
is parsed JSONClient
promises a raw HTTP fetch response according to the standard
Confused yet? This #get
example should make the difference clear:
var standardClient = 'https://app.firebaseio.com' auth: 'SECRET' ;var jsonClient = 'https://app.firebaseio.com' auth: 'SECRET' ; standardClient jsonClient
If you're still confused, see "Client
vs JSONClient
" below for a deep dive.
You make the following requests with either client:
// Reading data (GET)client;client; // Writing data (PUT)client;client; // Updating data (PATCH)client;client; // Pushing data (POST)client;client; // Removing data (DELETE)client;client;
additionalQueryParams
: Additional URL params to merge with the default params provided (e.g.{ orderBy: '$value', limitToFirst: 2 }
,{ shallow: true }
.)'/path'
: Path to a part your DB, no/
required.payload
: Object to write to Firebase
FirebaseREST
also provides aliases to match the semantics of the official Firebase JavaScript library:
clientset === clientput; // => trueclientupdate === clientpatch; // => trueclientpush === clientpost; // => trueclientremove === clientdelete; // => true
Client
vs JSONClient
You can see the differences when comparing two GET requests. TLDR, you probably want to use JSONClient
: it's supremely convenient.
//// Standard Client// var responsePromise = client// => Body {// url: 'https://app.firebaseio.com/.json?auth=SECRET',// status: 200,// statusText: 'OK',// headers: Headers { ... },// ok: true,// body: PassThrough { ... },// ... }responsePromise// => { db: 'contents' } //// JSON Client// jsonClient// =>// JSONResponse {// url: 'https://app.firebaseio.com/.json?auth=SECRET',// status: 200,// statusText: 'OK',// headers: Headers { ... },// ok: true// body:// { db: 'contents' }
More Documentation and Examples
See the source and the specs. There be hidden treasure.