resource-mapper
v0.0.1
Published
A fast and router-agnostic resource mapper for generating pragmatic RESTful API routes.
Downloads
5
Maintainers
Readme
resource-mapper
A fast and router-agnostic resource mapper for generating pragmatic RESTful API routes.
Install
npm install resource-mapper
Quick start
var ResourceMapper = require('resource-mapper');
// for example, using ExpressJS router.
// See 'Routers' section below to see a list of supported routers
var router = require('express').Router();
var mapper = new ResourceMapper(router);
// map a collection resource
mapper.collection('users', {
list: function (req, res), // GET /users (retrieves a list of users)
create: function (req, res), // POST /users (creates a new user)
show: function (req, res), // GET /users/:id (retrieves a specific user)
edit: function (req, res), // PUT /users/:id (edit an existing user)
update: function (req, res), // PATCH /users/:id (partially update an existing user)
destroy: function (req, res), // DELETE /users/:id (deletes an existing user)
});
// map a singleton resource
mapper.collection('account', {
show: function (req, res), // GET /account (retrieves account singleton)
create: function (req, res), // POST /account (create account)
edit: function (req, res), // PUT /account (edit account)
update: function (req, res), // PATCH /account (partially update account)
destroy: function (req, res), // DELETE /account (deletes account)
});
Concepts
Resources: Collections vs Singleton
Pragmatic RESTful APIs
Tests
npm test
Note: Requires mocha to be installed
[sudo] npm install mocha -g
Known Issues
Links
License
Copyright (c) 2014 Hafiz Ismail. This software is licensed under the MIT License.