New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cf-api

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cf-api

A pluggable JSON API server

  • 0.5.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
60
increased by114.29%
Maintainers
1
Weekly downloads
 
Created
Source

cf-api

A pluggable JSON API server

This is CatfishApi but without all of the bloat and a simple API to register plugins. Everything becomes a plugin.

Installation

npm install --save cf-api

Usage

var serviceLocator = require('service-locator').createServiceLocator()
  , api = require('cf-api')

// Register your services on the serviceLocator here…

api(options)
  .plugins([ require('./path/to/plugin'), require('./path/to/other/plugin') ])
  .initialize(serviceLocator, function (err, server) {
    if (err) throw err
    server.listen(1337)
  })

A plugin is just a node module with a single synchronous function exported:

module.exports = init

function init(serviceLocator, router) {
  // Do plugin things…
}

API API

var api = createApi(Object: options)

Create an API instance. There are two options available:

  • allowedDomains - a whitelist of allowed domains that cross-domain requests may come from (default: [])
  • logger - a logger object with methods debug(), info(), warn() and error() (default: console)

api.plugins(Array: plugins) or api.plugin(Function: plugin)

Register a list of plugins (or a single plugin). These are not run when they are registered, but when initialize() is called.

Returns api for chaining.

api.initialize(Object: serviceLocator, Function: cb)

Create the server, initialize all of the plugins and callback with the server. Plugin initialize functions are called with the following arguments: plugin(serviceLocator, router).

Plugins are initialized in the order that they were passed to plugin().

serviceLocator is a place where your plugins can speak to application level services. It could be a plain JS object, but it's better to use something like serby/service-locator to prevent naming clashes.

cb(err, server) is called when all plugins have been initialized (err=null), or on the first error (err!=null).

Credits

Built by developers at Clock.

Licence

Licensed under the New BSD License

FAQs

Package last updated on 26 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc