Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Modified the post, put, head and del shortcuts to support uri optional param #180

Merged
merged 1 commit into from

2 participants

@twilson63

Now you should be able to do the following:

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:

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

request.post = function (uri, options, callback) {
  var params = initParams(uri, options, callback);
  params.options.method = 'POST';
  return request(params.uri, params.options, params.callback)
}
@mikeal mikeal merged commit 56d868d into from
@cybdoom cybdoom referenced this pull request from a commit in cybdoom/EbayAmazonApiServer
@cybdoom cybdoom