@alex2844/js-global-fetch

1.1.0 • Public • Published

globalFetch

Version

Universal Fetch API, FormData, AbortController, CorsProxy for Nodejs and Browsers

Install

nodejs
npm install js-global-fetch
cdn
<script src="https://alex2844.github.io/js-global-fetch/dist/polyfill.js"></script>

Usage

Get json
const { fetch } = require('js-global-fetch');
fetch('https://httpbin.org/get', {
    headers: {
        'Cors-Referer': 'https://alex2844.github.io/js-global-fetch/',
        'Cors-User-Agent': 'globalFetch'
    }
})
    .then(res => res.json())
    .then(body => console.log(body));
CorsProxy as a plugin for Fastify
const
    Fastify = require('fastify'),
    { CorsProxy } = require('js-global-fetch');
(Fastify()
    .register(CorsProxy, { prefix: '/proxy' }) // http://localhost:3000/proxy/
    .get('/', async (req, rep) => 'Index page') // http://localhost:3000/
    .listen(3000, () => console.log('Server start'))
);

Run cli

PORT=3000 globalFetch

Demo and tests

https://alex2844.github.io/js-global-fetch/

Readme

Keywords

none

Package Sidebar

Install

npm i @alex2844/js-global-fetch

Weekly Downloads

3

Version

1.1.0

License

none

Unpacked Size

53.2 kB

Total Files

5

Last publish

Collaborators

  • alex2844