Skip to content

Instantly share code, notes, and snippets.

@jhs
Created December 15, 2011 03:59
Show Gist options
  • Save jhs/1479779 to your computer and use it in GitHub Desktop.
Save jhs/1479779 to your computer and use it in GitHub Desktop.
request input validation
var request = require('request')
, db = 'http://localhost:5984/my_db'
request.put(db, function(er, res) {
// This never happens. You need a body in an options object.
})
request.put({uri:db, body:'blah'}, function(er, res) {
// This is the normal API. It's fine.
})
request({PUT:db, body:'blah'}, function(er, res) {
// Slightly shorter. I like it, but reasonable people could disagree.
})
request({GET:db, PUT:db, body:'blah'}, function(er, res) {
// Mikeal says it opens the door to bad code like this.
// My solution would be for this to throw an error.
})
request.get({method:'PUT', body:'blah'}, function(er, res) {
// This works today but it is equally stupid. You have to read
// the code to know what you'll get. for request.get(), you get
// the method in the options. For .post(), .put(), etc., the options
// method is ignored.
//
// So this should probably throw too while we're at it.
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment