New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fetch-h2

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-h2

HTTP/1+2 Fetch API client for Node.js

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is fetch-h2?

The fetch-h2 npm package is a modern HTTP/2 client for Node.js, providing a fetch API compatible interface. It allows you to make HTTP/2 requests with ease, leveraging the benefits of HTTP/2 such as multiplexing, header compression, and server push.

What are fetch-h2's main functionalities?

Basic HTTP/2 GET Request

This feature allows you to make a basic HTTP/2 GET request to a specified URL and log the response body.

const { fetch } = require('fetch-h2');

(async () => {
  const response = await fetch('https://example.com');
  const body = await response.text();
  console.log(body);
})();

HTTP/2 POST Request with JSON Body

This feature allows you to make an HTTP/2 POST request with a JSON body to a specified URL and log the JSON response.

const { fetch } = require('fetch-h2');

(async () => {
  const response = await fetch('https://example.com/api', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ key: 'value' })
  });
  const json = await response.json();
  console.log(json);
})();

Handling HTTP/2 Server Push

This feature demonstrates how to handle server push in HTTP/2, where the server can send additional resources to the client without the client explicitly requesting them.

const { fetch } = require('fetch-h2');

(async () => {
  const response = await fetch('https://example.com');
  response.on('push', (pushStream) => {
    pushStream.on('data', (chunk) => {
      console.log('Pushed data:', chunk.toString());
    });
  });
})();

Other packages similar to fetch-h2

Keywords

FAQs

Package last updated on 15 May 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