se7ensky-restify-resource

1.2.1 • Public • Published

se7ensky-restify-resource

Pretty resource routing for restify.

Features

  • simple and unobtrusive usage
  • good logging
  • mapping whole resource to uri
  • relative route mapping in resource

Installing

$ npm install se7ensky-restify-resource

Usage

server.coffee:

...
log = bunyan.createLogger ...
server = restify.createServer ...
server.use ...
...
 
require('se7ensky-restify-resource')(serverlog"#{__dirname}/resources") # initialize module 
 
server.resource 'items' # initialize resource under URI '/items' 

resources/items.coffee

customers = [
  { id: 1title: 'item 1' }
  { id: 2title: 'item 2' }
  { id: 3title: 'item 3' }
]
 
GET ->
  @res.send customers
GET ':id'->
  @res.send customers[@req.params.id]
POST ->
  customers.push { id: @req.body.idtitle: @req.body.title }
  @res.send customers[@req.params.id]
PUT ':id'->
  customers[@req.params.id= { id: @req.body.idtitle: @req.body.title }
  @res.send customers[@req.params.id]
DELETE ':id'->
  @res.send customers[@req.params.id]
  delete customers[@req.params.id]
 
exampleMiddleware = ->
  @test = 5
GET 'test'exampleMiddleware->
  @res.send @test

ToDo

  • initialization and configuration flexibility
  • better logging facilities
  • more middleware syntax sugar

Contributing

Feel free to post issues or pull requests at github repo.

Authors

License

(The MIT License)

Copyright (c) 2008-2013 Se7enSky studio <info@se7ensky.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,

Readme

Keywords

none

Package Sidebar

Install

npm i se7ensky-restify-resource

Weekly Downloads

7

Version

1.2.1

License

none

Last publish

Collaborators

  • krava