Simple wrapper over window.fetch
<script src="node_modules/fetchio/dist/main.bundle.js"></script>
<script>
var fetchio = fetchio.default;
</script>
var fetchio = require('fetchio')['default'];
import fetchio from 'fetchio'
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
- whatwg-fetch
- url-join
MIT