h2io-fetch
v0.0.2
Published
Fetch wrapper used inside H2io modules
Downloads
4
Readme
H2io - Fetch
Installation
npm install h2io-fetch
Usage
GET
import { jsonFetch } from 'h2io-fetch';
jsonFetch('//example.com')
.then((obj) => console.log('response obj', obj))
.catch((e) => throw new Error(e));
POST
If we pass body
fetch method will be post
import { jsonFetch } from 'h2io-fetch';
const body = {
firstName: 'John',
lastName: 'Doe',
};
jsonFetch('//example.com', { body })
.then((obj) => console.log('response obj', obj))
.catch((e) => console.error(e));
Options (default)
const opts = {
method: 'get',
mode: 'cors',
credentials: 'include',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
}