fetchio

1.0.0 • Public • Published

Fetchio

Simple wrapper over window.fetch

How to use

Include to project

Global

<script src="node_modules/fetchio/dist/main.bundle.js"></script>
<script>
    var fetchio = fetchio.default;
</script>

CommonJS

var fetchio = require('fetchio')['default'];

ES6

import fetchio from 'fetchio'

Usage

const Api = fetchio.Init({
  baseUrl: 'https://api.example.com',
  requestInterceptor: function (req) {
    // do some stuff
    return req
  },
  fetch: {/*...*/}
})
Api.Fetch('users', { headers: {/*...*/} }, { userId: 1 })
// GET https://api.example.com/users?userId=1
// return Promise
Api.Fetch('users', {
  method: 'post',
  body: JSON.stringify(user)
})
// POST https://api.example.com/users
// return Promise

Dependencies

  • whatwg-fetch
  • url-join

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i fetchio

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • nurislamov