Last active
August 29, 2015 14:00
-
-
Save laser/11158892 to your computer and use it in GitHub Desktop.
Batching createTodo Calls on Client
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
// 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