Created
May 12, 2014 20:30
-
-
Save laser/4f12c75cb429e51815b6 to your computer and use it in GitHub Desktop.
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
// initialize the API client | |
function initApp(callback) { | |
function transport(req, callback) { | |
var settings = { | |
type: 'POST', | |
contentType: 'application/json', | |
data: JSON.stringify(req), | |
beforeSend: function(xhr) { | |
// set the Authorization header | |
xhr.setRequestHeader('Authorization', 'Basic ' + btoa('admin:admin')); | |
}, | |
success: function(data) { | |
callback(data); | |
} | |
}; | |
jQuery.ajax('/todos', settings); | |
}; | |
var client = Barrister.httpClient(transport); | |
client.loadContract(function() { | |
var proxy = client.proxy('TodoManager'); | |
callback(null, proxy); | |
}); | |
} | |
// consume the API client | |
initApp(function(err, TodoManager) { | |
TodoManager.readTodos(function(err, todos) { | |
jQuery('#result').text(JSON.stringify(todos)); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment