Skip to content

Luphia/ecRequest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ecRequest

An easy way to request http and https

Install

npm install ecrequest

Use

const ecrequest = require('ecrequest');
const opt = {
  protocol: 'https:',
  host: 'www.google.com',
  port: 80,
  hostname: 'www.google.com',
  pathname: '/',
  path: '/',
  timeout: 1000
};

### request ###
ecrequest.request(opt).then(console.log);

### error handling ###
async run() => {
  try {
    console.log(`START`);
    await ecrequest.request(opt).then(console.log);
    console.log(`DONE`);
  } catch(e) {
    console.log(`ERROR ${e.message}`);
  }
}
run();

### get ###
ecrequest.get(opt).then(console.log);

### post ###
opt.data = { post: 'body' };
ecrequest.post(opt).then(console.log);

### put ###
opt.data = { put: 'body' };
ecrequest.put(opt).then(console.log);

### delete ###
opt.headers = { 'content-type': 'application/json' };
ecrequest.delete(opt).then(console.log);

About

An easy way to request http and https

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published