Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 20, 2012

Conversation

twilson63
Copy link
Contributor

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 added a commit that referenced this pull request Feb 20, 2012
Modified the post, put, head and del shortcuts to support uri optional param
@mikeal mikeal merged commit 56d868d into request:master Feb 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants