Skip to content

Commit

Permalink
fix the way http verbs are defined
Browse files Browse the repository at this point in the history
I changed the way they are defined so that they are more IDE-friendly. The way they were defined, an IDE wouldn't easily recognize them and would often show 'request.get' or 'request.post' etc as a possible error. Ctrl+clicking on the 'get' function wouldn't take you to where it was defined. Now it will!
  • Loading branch information
samjross committed May 24, 2015
1 parent f2451bf commit f5eaea8
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions index.js
Expand Up @@ -56,16 +56,23 @@ function request (uri, options, callback) {
return new request.Request(params)
}

var verbs = ['get', 'head', 'post', 'put', 'patch', 'del']

verbs.forEach(function(verb) {
var method = verb === 'del' ? 'DELETE' : verb.toUpperCase()
request[verb] = function (uri, options, callback) {
var params = initParams(uri, options, callback)
params.method = method
return request(params, params.callback)
}
})
(function(){
var verbFunc = function(verb){
var method = verb === 'del' ? 'DELETE' : verb.toUpperCase();
return function (uri, options, callback) {
var params = initParams(uri, options, callback);
params.method = method;
return request(params, params.callback)
}
};

request.get = verbFunc('get');
request.head = verbFunc('head');
request.post = verbFunc('post');
request.put = verbFunc('put');
request.patch = verbFunc('patch');
request.del = verbFunc('del');
})();

request.jar = function (store) {
return cookies.jar(store)
Expand Down

0 comments on commit f5eaea8

Please sign in to comment.