Restie
Restie is a ORM that talks to RESTful interface, rather than database. For Node.js and browsers.
Installation
Browser (requires jQuery, 2.9kb minified and gzipped):
<!-- jQuery must be included before -->
Node.js:
npm install restie
Usage
The cute thing about Restie is that you can use it the same way on Node.js and in browsers, without any code changes.
Initialization
Restie;
Model Declaration
var Post = Restie; // short way, requests will go to http://localhost:8080/posts var Post = Restie;
Finding all items
Postall{ // GET /posts/ // posts is an array of Post models, so you can manipulate them via ORM-like methods};
Finding one item
Post;
Warning. When you declare primaryKey, Restie looks for it and declares two methods:
- find_by_[primary key] - for underscore lovers
- findBy[primary key] - for underscore haters
So, if you will set 'title' as your primary key, Post model will have these methods available:
- find_by_title
- findByTitle
Support for parameters in find operation will be implemented soon.
Creating items
// Slow (speed of code writing) var post = ;posttitle = 'New Post';postbody = 'Content of the post';post; // Faster var post = title: 'New Post' body: 'Content of the post' ;post; // Fastest Post;
Updating items
Post;
Removing items
Post;
Tests
Before you run each batch of tests, you should start/restart test application:
node test/server.js
Run tests for browser:
open http://localhost:8080/test.html
Run tests for Node.js:
mocha test/nodejs/*
Contributing
- Fork
- Write code, build using
grunt
- Write tests for that code
- Commit & push
- Send pull request
License
(The MIT License)
Copyright (c) 2011 Vadim Demedes sbioko@gmail.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, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.