facet

extensible, framework agnostic JSON API platform for Node.js

Download .zip Download .tar.gz View on GitHub

Facet Core

Base object that provides common functionality and gets extended by the other facet modules. Core offers access to the following functionality:

  • Abstration of middleware specific code for framework agnostic use
  • Handling of request/response lifecycle
  • Built in CRUD functionality via find, findOne, create, update, delete functions for any resource you create
  • Management of event bus (aka Intercom) used for decoupled module communication

Example

"use strict";
var util = require('util'),
  ApiCore = require('facet-core').ApiCore;

var ProductAPI = function ( options ){};

/**
 * Product API inherits from Core API
 */
util.inherits(ProductAPI, ApiCore);

// query.conditions, query.fields, and query.options 
// are regular mongoose queries
var query = {
  conditions: {name: 'Cool Item'},
  fields: '',
  options: {
    lean: true
  }
}

// FacetApiCore.find() is a wrapper for mongoose's find(), same 
// with findOne(), create(), remove() and update()
ProductAPI.find(query, successCb, errorCb);
facet is maintained by facet