Sourcery is a framework for building RESTful API clients. It's heavily inspired by ActiveResource and behaves almost the same way. It's blazing fast and extremely simple to use.
var Resource = require'sourcery';var Base = Resourceextendhost: '' // base hostext: 'json' // optional, will include `.json` in the URLsroot: true // optional, will include root element;var Project = Baseextendpath: '/projects' //name: 'Project' // optional, this is the name for the root element;
Projectfirst id: 1projectget'name';projectget'id';;
Projectall user_id: 1projects0get'user_id';projects1get'user_id';;
var project = ;projectset'name' 'Top secret';projectsaveconsole.logproject;;
Projectcreate name: 'Secret'console.logproject;;
var project = id: 1 ;projectset'name' 'New name';projectsaveconsole.logproject;;
var project = id: 1 ;projectdestroy// done;
Projectwhere'page' 1where'limit' 3allconsole.logprojects;;
var Task = Baseextendpath: '/projects/:project_id/tasks';
Sourcery will replace the placeholders, in this example ":project_id", with the matching attribute.
var BasicAuth = require'sourcery'BasicAuth;var Base = Resourceextendhost: ''auth:type: BasicAuthuser: 'replace-with-real-user'pass: 'replace-with-real-pass';
Please open issues if you have feature requests. Thanks!
$ npm install sourcery
$ npm install$ make test
Copyright (C) 2012 Veselin Todorov (firstname.lastname@example.org)
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.