0.0.2 • Published 8 years ago

h2io-fetch v0.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
8 years ago

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',
  },
}