Fitch.js
A lightweight Promise based HTTP client, using Fetch API.
Get started
Read the full Documentation
Install
npm i --save fitch
Use
With ES2015 or TypeScript:
import fitch from 'fitch'
CommonJS:
const fitch = require('fitch')
UMD:
<script src="node_modules/fitch/dist/index.umd.min.js"></script>
Make your first request:
fitch.get(apiUrl)
.then(data => console.log(data))
Methods available:
get
fitch.get(apiUrl)
.then(data => console.log(data))
post
const req = {body: {name: 'Happy cat'}}
fitch.post(apiUrl, req)
.then(data => console.log(data))
put
const req = {body: {name: 'Happy cat'}}
fitch.put(apiUrl, req)
.then(data => console.log(data))
patch
const req = {body: {name: 'Happy cat'}}
fitch.patch(apiUrl, req)
.then(data => console.log(data))
del
fitch.del(apiUrl)
.then(data => console.log(data))
Use with custom configuration
const config = {
cache = 'no-store',
headers = { 'Content-Type': 'application/json' },
mode = 'no-cors',
params: {
test1: 'test-1',
test2: 'test-2',
},
raw = true,
redirect: 'follow',
}
fitch.get(apiUrl, config)
.then(data => console.log(data))
See more about fetch configuration at: Fetch API.
Browser Support
| | | | |
| --------- | --------- | --------- | --------- | --------- | --------- |
| IE10, IE11, Edge| Every versions| Every versions| 6.1+|
Note: modern browsers such as Chrome, Firefox, and Microsoft Edge contain native implementations of window.fetch, so the polyfill doesn't have any affect on those browsers. See more at window.fetch polyfill.
Contributig
First yout need to fork this repository. Then:
npm i
npm start
npm run watch:test
npm run examples
Note: Your code must be tested and pass in linter check.
You can verify your code with ESLint, using npm run lint
.