ORM that operates with RESTful interface, rather than database.
Restie is a ORM that talks to RESTful interface, rather than database. For Node.js and browsers.
Browser (requires jQuery):
<!-- jQuery must be included before -->
npm install restie
The cute thing about Restie is that you can use it the same way on Node.js and in browsers, without any code changes.
Restieseturls:base: '' // base URL for all models, can be over-written for each of themwrapFields: yes // post[title] instead of just title field in POST bodyprimaryKey: 'id' // primary keydefaults: // default headers, fields and querystring params for all requestsheaders:'X-Authorization': '12345'fields:'_csrf_token': '12345'params:'_csrf_token': '12345';
var Post = Restiedefine'Post'; // short way, requests will go tovar Post = Restiedefine'Post' // long waywrapFields: no // override params for that model;
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
Postfind_by_id1 // GET /posts/1posttitle; // access post's fields just like that;
Warning. When you declare primaryKey, Restie looks for it and declares two methods:
So, if you will set 'title' as your primary key, Post model will have these methods available:
Support for parameters in find operation will be implemented soon.
// Slow (speed of code writing)var post = ;posttitle = 'New Post';postbody = 'Content of the post';postsave // POST /postspostid; // post now has an id field;// Fastervar post = title: 'New Post' body: 'Content of the post' ;postsave // POST /postspostid;;// FastestPostcreate title: 'New Post' body: 'Content of the post' // POST /postspostid;;
Postfind_by_id1 // PUT /posts/1posttitle = 'New title';postsave// post updated;;
Postfind_by_id1 // DELETE /posts/1postremove// post removed;;
Before you run tests, you should start test application:
Run tests for browser:
Run tests for Node.js:
First of all, run
jake -T to see list of available tasks. After you made some changes, do this:
coffee -cb test/nodejs/restie.test.coffee && mv test/nodejs/restie.test.coffee test/browser/restie.test.js
(The MIT License)
Copyright (c) 2011 Vadim Demedes email@example.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.