A nutritious grain to create friendly, consumable API functions.
Dinkels are also used to create delicious bread.
npm install dinkel
var Dinkel = require('dinkel');
// Declare the API service base path and endpoints
var api = new Dinkel('http://api.example.com/', [
'users',
'widgets/:id'
]);
Methods are generated based on the endpoint routes. For example api.Users
and api.Widgets
, in the example above.
// Watch the response data for changes
var data = api.Users.get().json();
// The data object is modified when data is received
Object.observe(data, function (changes) {
// Do something with the returned JSON
console.log(changes);
});
// Make API calls and use promises to handle responses
api.Users.get()
.then(function (data) {
// Do something with the returned JSON
console.log(data);
})
.catch(function (err) {
// Handle the error
console.warn(err);
});
var data = {};
api.Users.get({}, data);
// The data object is modified when data is received
Object.observe(data, function (changes) {
// Do something with the returned JSON
console.log(changes);
});
See urlbuilder for details.
Coming soon
npm test