npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

firebase-rest

v1.0.0

Published

REST Client for Firebase

Downloads

20

Readme

Firebase REST Client for Node :fire:

Build Status npm version Dependencies

  • 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 = require('firebase-rest').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 JSON
  • Client promises a raw HTTP fetch response according to the standard

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

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

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 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
//

var 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.