From 8485e67df322cea0e7e8bd9f22d40bcf6be67651 Mon Sep 17 00:00:00 2001 From: Samuel Marks Date: Fri, 1 Apr 2016 15:08:03 +1100 Subject: [PATCH] Added remaining HTTP shortcut methods Docs for HTTP GET shortcut method https://nodejs.org/api/http.html#http_http_get_options_callback --- lib/http.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/http.js b/lib/http.js index 64788dd5c07f9f..34fdeb42a23ac0 100644 --- a/lib/http.js +++ b/lib/http.js @@ -31,11 +31,22 @@ exports.request = function(options, cb) { return new ClientRequest(options, cb); }; -exports.get = function(options, cb) { - var req = exports.request(options, cb); - req.end(); - return req; -}; +function shortcutMethod(method) { + return function(options, cb) { + options['method'] = method; + var req = exports.request(options, cb); + req.end(); + return req; + } +} + +exports.get = shortcutMethod('GET'); +exports.head = shortcutMethod('HEAD'); +exports.post = shortcutMethod('POST'); +exports.put = shortcutMethod('PUT'); +exports.del = shortcutMethod('DELETE'); +exports['delete'] = exports.del; +exports.patch = shortcutMethod('PATCH'); exports._connectionListener = server._connectionListener; const Server = exports.Server = server.Server;