Socket
Socket
Sign inDemoInstall

real-isomorphic-fetch

Package Overview
Dependencies
20
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    real-isomorphic-fetch

Isomorphic fetch() with cookie 🍪 and redirect ⏩ support for all environments


Version published
Weekly downloads
134
decreased by-8.84%
Maintainers
1
Install size
346 kB
Created
Weekly downloads
 

Readme

Source

real-isomorphic-fetch Build Status

Isomorphic fetch() with cookie 🍪 and redirect ⏩ support for all environments

Installation

npm install real-isomorphic-fetch --save

Usage

const IsomorphicFetch = require('real-isomorphic-fetch');
const fetch = require('node-fetch'); // could also be window.fetch in the browser or global.fetch in react-native
const fetchInstance = new IsomorphicFetch(fetch) // cookies are shared between every IsomorphicFetch instance

fetchInstance('https://example.com/123') // Cookies and redirects are handled automatically
.then(response => response.text())
.then(text => console.log(text))
.catch(err => console.error(err));

The problem

const fetchWithCookie = require('fetch-cookie')(require('node-fetch'));
fetchWithCookie('https://example.com/123', {
	redirect: 'manual'
})
.then(response => response.headers.get('Location'))
.then(location => fetchWithCookie(location, {redirect: 'manual'}))
  • ... which then doesn't work in the browser anymore because you can't intercept redirects (and because it uses native dependencies)!

The solution

This library handles cookies and redirects together and normalizes the behaviour of node-fetch to match the one of the browser, so you can use the same syntax in both environments.

Credits

This is a rewrite of fetch-cookie. Heavy inspiration also from isomorphic-fetch.

License

MIT © Jonny Burger

Keywords

FAQs

Last updated on 28 Jul 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc