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

facet-platform

v0.1.0

Published

Orchestration of facet modules for rapid API development

Downloads

1

Readme

Facet Platform

Provides extensible common utility classes for rapid JSON API development. Offers 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

Examples

Creating a new resource API class

See the facet core module for details on creating API resources.

var ApiCore = require('facet-core').ApiCore;

var TodosAPI = function(facet.moduleOptions) {
  // define mongoose schema and bind events here
  // see other facet modules for examples:
  //   https://github.com/facet/gatekeeper
  //   https://github.com/facet/category
  //   https://github.com/facet/catalog
};

/**
 * Todos API inherits from API Core which enables CRUD functionality.
 * The definition of new facet classes would be done in a different 
 * module which depends on facet-core
 */
util.inherits(TodosAPI, ApiCore);

Setting up a JSON API server using express 4

var facet = require('facet-platform')(),
  app = require('express')();

// set up facet modules
facet
  .useModules({
    'todo': require('./path-to-todos')
  })
  .setModuleOptions({dbServer: 'mongodb://localhost:27017'})
  .init(app);

app.use(bodyParser.json());
app.set('port', process.env.PORT || 9393);

// auto route binding for CRUD routes:
// GET /todos
// GET /todos/:id
// POST /todos
// PUT /todos/:id
// DELETE /todos/:id
// Advanced route binding across different domains is
// possible as well. See The facet-commerce for an example.
app.use( '/api/v1', facet.getModule('todo').bindRoutes( express.Router(), {
  routeBase: '/todos'
}));
  
http.createServer(app).listen(8888, function(){
  console.log('Express server listening on port 8888');
});

Also checkout out the sample app.

Using CRUD functions directly or in custom implementations

var facet = require('facet-platform');

// create a todo
var importantTodo = {
  author: 'Action Bronson',
  task: 'Kick back'
}

todosAPI.create(importantTodo)
  .then(function(data) {
    console.log('created task: ', data);
  },
  function(err) {
    console.log('booo: ', err);
  })
  .end();

// query.conditions, query.fields, and query.options 
// are regular mongoose queries
var findQuery = {
  conditions: {task: 'Kick back'},
  fields: '',
  options: {
    lean: true
  }
}

// TodosAPI.find() is a wrapper for mongoose's find(), same 
// with findOne(), create(), remove() and update()

TodosAPI.find(query, successCb, errorCb);

// or via promises

TodosAPI.find(query)
  .then(function(data) {
    console.log('success! ', data);
  },
  function(err) {
    console.log('booo: ', err);
  })
  .end();

Coming Soon...

  • actual documentation and example apps
  • multitenancy support w/ multiple apps per tenant
  • error handling base class
  • logging functionlality