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

isomorphic-unfetch

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

isomorphic-unfetch

Switches between unfetch & node-fetch for client & server.

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.3M
decreased by-1.38%
Maintainers
1
Weekly downloads
 
Created

What is isomorphic-unfetch?

The isomorphic-unfetch npm package is a lightweight module that allows for making HTTP requests in both Node.js and browser environments. It's designed to provide a consistent API for fetch across these environments, making it easier to write isomorphic code that runs on both the server and the client.

What are isomorphic-unfetch's main functionalities?

Basic GET Request

This code sample demonstrates how to perform a basic GET request to retrieve data from an API and print it to the console. It uses the fetch API to make the request, parses the response as JSON, and handles any errors that may occur.

fetch('https://api.example.com/data')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

POST Request with JSON Body

This example shows how to send a POST request with a JSON body. It sets the method to POST, includes a Content-Type header to indicate the type of the request body, and uses JSON.stringify to convert a JavaScript object to a JSON string. The response is then parsed as JSON.

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

Other packages similar to isomorphic-unfetch

FAQs

Package last updated on 17 Sep 2018

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