Giter VIP home page Giter VIP logo

node-firebase-rest's Introduction

Firebase REST Client for Node ๐Ÿ”ฅ

Build Status npm version Dependencies

  • Query support with proper JSON encoding.
  • Requests with the WHATWG Fetch API via node-fetch.
  • You can bring your own Promise library with FirebaseREST.setPromise(Promise).
  • Typescript (if you're into that.)

Installation

npm install firebase-rest --save

Usage

// Don't forget `.default` at the end! (We use ES6 modules from the future.)
const FirebaseREST = require('firebase-rest').default;

Instantiate either the FirebaseREST.JSONClient or the FirebaseREST.Client, and start making calls. What's the difference?

  • JSONClient promises a Fetch-like response where the #body is parsed JSON
  • Client promises a standards compliant Fetch response

Confused yet? This #get example should make the difference clear:

// First instantiate a client with any default query parameters such as auth
var standardClient =
  new FirebaseREST.Client('https://app.firebaseio.com', { auth: 'SECRET' });

var jsonClient =
  new FirebaseREST.JSONClient('https://app.firebaseio.com', { auth: 'SECRET' });

// Then start making requests
standardClient.get('/')
  .then(res => res.json())
  .then(json => /* do something with the json */);

jsonClient.get('/')
  .then(res => /* do something with the res.body */);

If you're still confused, see "Client vs JSONClient" below for a deep dive.

You can make the following requests with either client:

// Reading data (GET)
client.get('/path');
client.get('/path', additionalQueryParams);

// Writing data (PUT)
client.put('/path', payload);
client.put('/path', payload, additionalQueryParams);

// Updating data (PATCH)
client.patch('/path', payload);
client.patch('/path', payload, additionalQueryParams);

// Pushing data (POST)
client.post('/path', payload);
client.post('/path', payload, additionalQueryParams);

// Removing data (DELETE)
client.delete('/path');
client.delete('/path', additionalQueryParams);
  • 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:

client.set === client.put;       // =>  true
client.update === client.patch;  // =>  true
client.push === client.post;     // =>  true
client.remove === client.delete; // =>  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
//

const responsePromise = client.get('/').then(res).then(console.log);
// => Body {
//   url: 'https://app.firebaseio.com/.json?auth=SECRET',
//   status: 200,
//   statusText: 'OK',
//   headers: Headers { ... },
//   ok: true,
//   body: PassThrough { ... },
//   ... }
responsePromise.then(res => res.json()).then(console.log);
// => { db: 'contents' }

//
// JSON Client
//

jsonClient.get('/').then(console.log);
// => 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.

node-firebase-rest's People

Contributors

fny avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.