Created
March 17, 2012 16:48
-
-
Save nagyv/2062210 to your computer and use it in GitHub Desktop.
Creating JSON request browser with Tobi
This file contains 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
var tobi = require('tobi'), | |
browser = tobi.createBrowser(8000, "localhost"); | |
json_browser = (function(){ | |
var json_header = {headers: | |
{ | |
"Accept": "application/json", | |
"X-Requested-With": "XMLHttpRequest" | |
} | |
}; | |
var json_method = function(method){ | |
return function(path, options, callback){ | |
if(!callback) { | |
callback = options; | |
options = {}; | |
} | |
browser[method](path, _.defaults(options, json_header), callback); | |
}; | |
}; | |
return { | |
get: json_method('get'), | |
post: json_method('post'), | |
put: json_method('put'), | |
delete: json_method('delete') | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment