
Security News
npm Introduces minimumReleaseAge and Bulk OIDC Configuration
npm rolls out a package release cooldown and scalable trusted publishing updates as ecosystem adoption of install safeguards grows.
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 -->
<script src="restie.min.js"></script>
Node.js:
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.
Initialization
Restie.set({
urls: {
base: 'http://localhost:8080' // base URL for all models, can be over-written for each of them
},
wrapFields: yes, // post[title] instead of just title field in POST body
primaryKey: 'id', // primary key
defaults: { // default headers, fields and querystring params for all requests
headers: {
'X-Authorization': '12345'
},
fields: {
'_csrf_token': '12345'
},
params: {
'_csrf_token': '12345'
}
}
});
Model Declaration
var Post = Restie.define('Post'); // short way, requests will go to http://localhost:8080/posts
var Post = Restie.define('Post', { // long way
wrapFields: no // override params for that model
});
Finding all items
Post.all(function(err, posts){ // GET /posts/
// posts is an array of Post models, so you can manipulate them via ORM-like methods
});
Finding one item
Post.find_by_id(1, function(err, post){ // GET /posts/1
post.title; // 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.
Creating items
// Slow (speed of code writing)
var post = new Post;
post.title = 'New Post';
post.body = 'Content of the post';
post.save(function(err){ // POST /posts
post.id; // post now has an id field
});
// Faster
var post = new Post({ title: 'New Post', body: 'Content of the post' });
post.save(function(err){ // POST /posts
post.id;
});
// Fastest
Post.create({ title: 'New Post', body: 'Content of the post' }, function(err, post){ // POST /posts
post.id;
});
Updating items
Post.find_by_id(1, function(err, post){ // PUT /posts/1
post.title = 'New title';
post.save(function(err){
// post updated
});
});
Removing items
Post.find_by_id(1, function(err, post){ // DELETE /posts/1
post.remove(function(err){
// post removed
});
});
Before you run tests, you should start test application:
node test/server.js
Run tests for browser:
jake test:browser
Run tests for Node.js:
jake test:nodejs
First of all, run jake -T to see list of available tasks. After you made some changes, do this:
jake build:allcoffee -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 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.
FAQs
ORM that operates with RESTful interface, rather than database.
We found that restie demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
npm rolls out a package release cooldown and scalable trusted publishing updates as ecosystem adoption of install safeguards grows.

Security News
AI agents are writing more code than ever, and that's creating new supply chain risks. Feross joins the Risky Business Podcast to break down what that means for open source security.

Research
/Security News
Socket uncovered four malicious NuGet packages targeting ASP.NET apps, using a typosquatted dropper and localhost proxy to steal Identity data and backdoor apps.