A library for building web services ontop of CouchDB
A framework for creating a data model web service layer on top CouchDB using Restify.
npm install slipcover
The SlipCover.App class comes with some built in routes based on the model type
Method Route Function-------------------------------------------------------GET /<plural type> SlipCover.App.list()GET /<singular type>/:id SlipCover.App.get()PUT /<plural type> SlipCover.App.create()POST /<signular type>/:id SlipCover.App.update()DELETE /<singular type>/:id SlipCover.App.del()
The above using
user as the
type would look like this:
Method Route Function-------------------------------------------------------GET /users SlipCover.App.list()GET /user/:id SlipCover.App.get()PUT /users SlipCover.App.create()POST /user/:id SlipCover.App.update()DELETE /user/:id SlipCover.App.del()
Each SlipCover.App method has a coresponding SlipCover.model method that matches. So for SlipCover.App.get() there is a coresponding SlipCover.Model.get() that matches.
var restify = require'restify';var nano = require'nano''';var SlipCover = require'slipcover';var _ = require'underscore';var ExampleModel = SlipCoverModelextendtype: 'example'// You can setup a transformer for get, create, updates. This// gives you the ability to transfrom the data without touching// the route or model methods. This is a good way to deal with// models that need joins. An example would be fetching the Authors// for all the Blog posts.transformers:// do something to transform the datarecordname = recordfirst_name + ' ' + recordlast_name;callbacknull record;// By default there is no list method. This is because you will// typically need to setup a view for your list opperation. The// route is setup by default in the App so you just need to create// your list method for the model.thisconnview'examples' 'getByLastName' optionsif errreturn callbackerr;callbacknull datarows;;;var ExampleApp = SlipCoverAppextend// Just like backbone you can setup your own initialize methodinitialize: funciton options// You will need to bind the instance of this object to// your route methods._bindAllthis 'minimal';// Extend the default routes with your own.routes:'GET /example/:id/minimal': 'minimal'// The custom route methodthismodelgetreqparamsidif errreturn nexterr;delete examplefirst_name;delete examplelast_name;ressend200 example;;// Setup a connection to the databasevar exampleDb = nanodbuse'exampledb';// When you initlaize your model you will need to pass// the database connectionvar model = conn: exampleDb ;// Pass your model to the app as an options upon initializationvar app = model: model ;// Create your Restify servervar server = restifycreateServer;// Mount your application.appmountserver;
The MIT License (MIT) Copyright (c) 2012 Plus 3 Network
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, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.