Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

make-fetch

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

make-fetch

Implement your own `fetch()` with node.js streams

  • 2.3.4
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

make-fetch

Implement your own fetch() with node.js streams

Usage

npm i --save make-fetch
const makeFetch = require('make-fetch')
const fetch = makeFetch(async (request) => {
  const {
    url, // String representing request URL
    headers, // An object mapping header titles to values
    referrer, // An optional string specify the referrer 
    method, // The HTTP method, will always be uppercase, default is `GET`
    body, // An optional async iterable of buffers for the request body
    signal // An optional AbortSignal that you might want to listen to for cancellation
  } = request

  return {
    statusCode: 200, // Should specify the status code to send back
    headers: { // Optional object mapping response header titles to values
      "something": "whatever"
    },
    data: asyncIterator // Required async iterable for the response body, can be empty
  }
})

const response = await fetch('myscheme://whatever/foobar')
console.log(await response.text())

Gotchas

  • The response.body is an Async Iterable of Buffer objects rather than a WHATWG ReadableStream
  • Eventually ReadableStream will become async iterable so you'll be able to iterate either normally

Keywords

FAQs

Package last updated on 25 Aug 2022

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