From f5eaea8bd4628d8d9571fbd1864ff30f6ad57dba Mon Sep 17 00:00:00 2001 From: Kremlin Date: Sun, 24 May 2015 01:01:33 +0100 Subject: [PATCH] fix the way http verbs are defined 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! --- index.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 8bc39545c..aee205647 100755 --- a/index.js +++ b/index.js @@ -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)