halbone
An isomorphic library for setting up Backbone models from a HAL API. Uses Traverson underneath.
Example
var api = "http://api.com"; var Comments = BackboneCollection; api;api;
Options
You may optionall pass an options object as the third arugment...
api;
qs & headers
Convenience aliases for Traverson's qs & headers options.
params
Alias for Traverson's URI Templates.
api.bootstrap
It's a common practice to bootstrap data you fetched on the server to the client to avoid making extra requests. By passing the bootstrapped data into the bootstrap
option, halbone will immediately return the hydrated model without making extra requests if it finds _links.self.href
, otherwise be sure to pass in the "root" link of the resource and it'll continue to fetch the model like normal. e.g.
POST_DATA = {}; // A new resource so empty data
api.get(Post, 'posts', { bootstrap: POST_DATA }, functionn(err, post) {
// post is a single resource with a url drawn from the 'posts' link.
// Allowing you to POST to it with a normal post.save
});
Contributing
Please fork the project and submit a pull request with tests. Install node modules npm install
and run tests with npm test
.
License
MIT