Skip to content

Instantly share code, notes, and snippets.

@laser
Last active August 29, 2015 14:00
Show Gist options
  • Save laser/11158892 to your computer and use it in GitHub Desktop.
Save laser/11158892 to your computer and use it in GitHub Desktop.
Batching createTodo Calls on Client
// Initializing API Client (Barrister)
function initApp(callback) {
var client = Barrister.httpClient({
'endpoint': '/todos',
'interfaces': ['TodoManager']
});
client.loadContract(function() {
var batch, proxy;
batch = client.startBatch(),
proxy = batch.proxy('TodoManager');
callback(null, proxy);
});
}
// Batch-requesting to API (Barrister)
initApp(function(err, BatchTodoManager) {
for (var i = 0; i < 10; i++) {
BatchTodoManager.createTodo({
'title': 'title ' + i,
'completed': false
});
}
BatchTodoManager.send(function(err, results) {
for (var i = 0, len = results.length; i < len; i++) {
console.log(results[i].result);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment