Allow passing url object directly to http.request

Right now:

const parsedUrl = URL.parse(url)

const r = http.request({
  method: 'put',
  host: parsedUrl.host,
  path: parsedUrl.path,

}, res => {

  let json = '';

  res.on('data', d => {
    json += d;
  });

  res.once('end', () => {
    let js = JSON.parse(json);
    console.log('the json is:', js);
  });

})

🙁

but why not:

const parsedUrl = URL.parse(url)

const r = http.request({
  method: 'put',
  url: parsedUrl,     /// easier for newbies

}, res => {

  let json = '';

  res.on('data', d => {
    json += d;
  });

  res.once('end', () => {
    let js = JSON.parse(json);
    console.log('the json is:', js);
  });

})

things like this will make it much easier for newbies, I am hoping this is already fixed but according to latest typescript typings no.

1 possible answer(s) on “Allow passing url object directly to http.request