1.1.1-rc.2 • Published 5 years ago

njs-fetch v1.1.1-rc.2

Weekly downloads
4
License
GPL-3.0
Repository
github
Last release
5 years ago

njs-fetch

fetch for node.js

examples

simple get request

var fetch = require("njs-fetch");
fetch("http://example.com").then(res => {
  console.log(res.body);
})

advanced https request

var fetch = require("njs-fetch");
fetch({
  hostname: 'encrypted.google.com',
  port: 443,
  path: '/',
  method: 'GET'
}).then(res => {
  console.log(res.body);
})

simple post request

var fetch = require("njs-fetch");
var postData = JSON.stringify({question: cool});
fetch({
  hostname: 'www.test.com',
  port: 80,
  path: '/cool',
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': Buffer.byteLength(postData)
  }
}, postData).then(res => {
  console.log(res.body);
})