Socket
Socket
Sign inDemoInstall

fetchu

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetchu

nodejs http-client


Version published
Weekly downloads
60
increased by1100%
Maintainers
1
Weekly downloads
 
Created
Source

fetchu: universal http-client

npm version build status

Differences with fetch:

  • automatically handle json body (JSON.stringify a body that is an objet literal, and add the right header)
  • throws on http error status

Files:

  • fetchu-node.js: using http/https modules for NodeJS, light drop-in replacement for node-fetch
  • fetchu-browser.js: it wraps window.fetch
import fetchu from 'https://unpkg.com/fetchu';

await fetchu('https://cors-anywhere.herokuapp.com/http://example.com').then(r => r.text()) // <!doctype html><html ...
await fetchu('https://httpbin.org/get?test=foo').then(r => r.json()) // { args: { test: 'foo' }, ...
await fetchu('https://httpbin.org/post', {method: 'POST', body: {test: 'foo'}}).then(r => r.json()) // { args: {},..

// abort:
const ac = new AbortController()
fetchu('https://httpbin.org/get?test=foo', { signal: ac.signal }).then(console.log, console.error)
delay(10).then(() => ac.abort())

NodeJS specificities (coming from http/https builtins):

const fetchu = require('fetchu');
await fetchu({ path: '/v1.37/containers/json', socketPath: '/var/run/docker.sock' }).then(r => r.json()) // [ { Id: 'aa6...

// abort:
require('abortcontroller-polyfill/dist/abortcontroller-polyfill-only');
const ac = new AbortController()
fetchu('https://httpbin.org/get?test=foo', { signal: ac.signal }).then(console.log, console.error)
delay(10).then(() => ac.abort());
// or 
const signal = new EventEmitter(); // node.js native events.EventEmitter
fetchu('https://httpbin.org/get?test=foo', { signal }).then(console.log, console.error)
delay(10).then(() => signal.emit('abort'))

Keywords

FAQs

Package last updated on 01 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc