mikeal/request — pull request #180 by twilson63 (2012-02-19 14:25:28+00:00)
Title: Modified the post, put, head and del shortcuts to support uri optional param

Now you should be able to do the following:

``` javascript
request.post("http://example.com/widgets", function(e,r,b) { console.log(b) });
//or
request.post("http://example.com/widgets", { body: 'foo=bar'}, function(e,r,b) { console.log(b) });
//and still do
request.post({ uri: "http://example.com/widgets", body: 'foo=bar'}, function(e,r,b) { console.log(b) });
```

created a new function called initParams to reduce duplication:

``` javascript
function initParams(uri, options, callback) {
if ((typeof options === 'function') && !callback) callback = options;
if (typeof options === 'object') {
options.uri = uri;
} else if (typeof uri === 'string') {
options = {uri:uri};
} else {
options = uri;
uri = options.uri;
}
return { uri: uri, options: options, callback: callback };
}
```

and each shortcut method calls this method to organize the method params

``` javascript
request.post = function (uri, options, callback) {
var params = initParams(uri, options, callback);
params.options.method = 'POST';
return request(params.uri, params.options, params.callback)
}
```