seneca-jsonrest-api

A HTTP JSON REST API for Seneca entities

seneca-jsonrest-api - a Seneca plugin

Exposes your data entities as a REST API. For example, if you have a data entity called foo, then the following end points will become available:

  • GET /api/rest/foo: return a list of all foo entities
  • GET /api/rest/foo/:id: return a single foo entity by identifier
  • POST /api/rest/foo: create a new foo entity
  • PUT /api/rest/foo/:id: update a foo entity

You can use the plugin options to change the URL prefix, and to add additional behaviours.

Note that it is not necessary for the underlying entity to be persistent. You can define a virtual entity foo by providing actions for the patterns:

  • role:entity,name:foo,cmd:save
  • role:entity,name:foo,cmd:load
  • role:entity,name:foo,cmd:list
  • role:entity,name:foo,cmd:remove

You can seneca.use this plugin multiple times to create multiple independent API end points, so long as you specify different prefixes. The prefix option is used to create separate action patterns so that they do not conflict.

  • prefix: a custom prefix
  • pins: an array of entity pins, with properties name,base,zone. These define the data entities that will be exposed.

Current Version: 0.3.1

Tested on: Node 0.10.36, Seneca 0.6.1

Annotated Source Code.

If you're using this module, feel free to contact me on Twitter if you have any questions! :) @rjrodger

To install and add to the dependencies list in the package.json file for your project:

npm install seneca-jsonrest-api --save

And in your code:

var seneca = require('seneca')()
    .use( 'jsonrest-api' )