Skip to content

Instantly share code, notes, and snippets.

@balanza
Created October 27, 2015 00:29
Show Gist options
  • Save balanza/ace370036c4870708b2d to your computer and use it in GitHub Desktop.
Save balanza/ace370036c4870708b2d to your computer and use it in GitHub Desktop.
//a generic function to call api endpoints
function apiCall(host, method, endpoint, params, callback){
var url = host + endpoint;
http(method, url, params, callback);
}
//this is some API for a foo.com web service
var fooAPI = _(apiCall).partial('http://foo.com');
var foo_listPosts = _(fooAPI).partial('GET', '/posts');
var foo_savePost = _(fooAPI).partial('POST', '/post');
//this is some API for a bar.com web service
var barAPI = _(apiCall).partial('http://bar.com');
var bar_login = _(barAPI).partial('POST', '/login');
var bar_userInfo = _(barAPI).partial('GET', '/user', {sessionId: mySession});
//this is how you'll call the API above
foo_savePost({title: 'my post', text: 'lorem ipsum'}, function(err, result){});
bar_login({username: 'myuser', password: 'mypassword'}, function(err, result){});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment