backbone-faux-server
backbone-faux-server copied to clipboard
Enable remote loading of json data using addRoutes option
Couldn't find much documenation for handler method. Any help would be appreciated
The handler's signature and semantics are documented as part of addRoute.
Let me know if you need help with something more specific.
I'm trying to do following, since its an async call, the following code doesn't work. Is there a better way to do the following
fauxServer.addRoutes({
listContacts: {
urlExp: 'api/contacts',
httpMethod: 'GET',
handler: function(context) {
$.getJSON('mock\test-data.json', function(data) {
context.data = data;
});
}
}
});
Unfortunately, async handlers are not supported.
If you can't load the test data up front (so that you synchronously return them when the handler is invoked) I would suggest that you don't use BFS for this but rather override the relevant model's sync method to do the job. Something along the lines of
myModel.sync = function (method, model, options) {
if (method !== 'read') {
throw 'this will only work for GET';
}
return $.getJSON('mock\test-data.json', function (data) {
options.success(data);
});
};