Created
October 27, 2015 00:29
-
-
Save balanza/ace370036c4870708b2d 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
//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