Supafetch
Simple fetch wrapper inspired by axios
Installing
- Install some polyfills if you're supporting old browser, skip this if you aren't. ( Note: node and some modern browsers support fetch and promise natively )
yarn add es6-promise whatwg-fetch
- Install supafetch
yarn add supafetch
API
Core
supafetch /* GET */supafetch /* POST */supafetch /* DELETE */supafetch /* PUT */supafetch /* PATCH */
options is some configuration that u can use when request ( you can use all of fetch's options as well.
options = headers: 'Accept': 'application/json' // Content-Type that will effect request body's transformation. /* 1. 'application/json' [default] 2. 'multipart/form-data' 3. 'application/x-www-form-urlencoded' */ 'Content-Type': 'multipart/form-data' // Params for query string params: page: 1 limit: 15 // Request body that will be transformed data: email: 'username@example.org' password: 'secret' // ... see github's fetch
Set base URL
supafetch
To set default header, you can use
supafetch
Interceptors
supafetch supafetch // you still have to return request's config or response even though you don't modify it.
Example Usage
supafetchsupafetch supafetch
Background
Because axios doesn't support http caching out of the box, so we decided to write a simple wrapper on top of fetch which resembles axios' api.