Last active
August 29, 2015 14:01
-
-
Save laser/083ed1906993b851fdf3 to your computer and use it in GitHub Desktop.
Batch Client - JavaScript (browser)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var client = Barrister.httpClient("/v1/todos"); | |
client.loadContract(function() { | |
var batch = client.startBatch(); | |
var batchTodoManager = batch.proxy('TodoManager'); | |
batchTodoManager.createTodo({ 'title' : 'Call Mom', 'completed' : false }) | |
batchTodoManager.createTodo({ 'title' : 'Call Dad', 'completed' : false }) | |
batchTodoManager.createTodo({ 'title' : 'Wash car', 'completed' : false }) | |
batchTodoManager.createTodo({ 'title' : 'Eat Ham', 'completed' : false }) | |
batch.send(function(err, results) { | |
// either r.error or r.result will be set | |
for (var i = 0, len = results.length; i < len; i++) { | |
if (results[i].error) { | |
// results[i].error is a object containing code and message, which you can throw yourself, if desired | |
console.log(results[i].error.code); | |
} | |
else { | |
// result from a successful call | |
console.log(results[i].result); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment