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

@whatwg-node/node-fetch

Package Overview
Dependencies
Maintainers
1
Versions
548
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@whatwg-node/node-fetch

Fetch API implementation for Node

  • 0.0.1-alpha-20230117081522-969e299
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6M
decreased by-14.02%
Maintainers
1
Weekly downloads
 
Created

What is @whatwg-node/node-fetch?

@whatwg-node/node-fetch is a Node.js implementation of the Fetch API, which is a modern, promise-based way to make HTTP requests. It is designed to be a lightweight and efficient way to handle HTTP requests and responses, similar to the Fetch API available in web browsers.

What are @whatwg-node/node-fetch's main functionalities?

Basic GET Request

This feature allows you to make a basic GET request to a specified URL and handle the response. The response is converted to JSON and logged to the console.

const fetch = require('@whatwg-node/node-fetch');

fetch('https://jsonplaceholder.typicode.com/posts/1')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

POST Request with JSON Body

This feature allows you to make a POST request with a JSON body. The request includes headers to specify the content type and a body with the data to be sent.

const fetch = require('@whatwg-node/node-fetch');

fetch('https://jsonplaceholder.typicode.com/posts', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    title: 'foo',
    body: 'bar',
    userId: 1
  })
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Handling Response Headers

This feature demonstrates how to access and log the response headers from an HTTP request. The headers are logged before the response body is processed.

const fetch = require('@whatwg-node/node-fetch');

fetch('https://jsonplaceholder.typicode.com/posts/1')
  .then(response => {
    console.log('Headers:', response.headers.raw());
    return response.json();
  })
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Other packages similar to @whatwg-node/node-fetch

FAQs

Package last updated on 17 Jan 2023

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