zero-fetch
Yet another convenient wrapper around fetch, for browser and node.js.
Why
fetch
is good, but not easy enough- Minimal code for modern browsers.
axios
is still too big(5kb gzipped) - Minimal config
- Focused to RESTFul API
Installing
Using npm:
$ npm i -D zero-fetch
Using cdn:
<script src="https://unpkg.com/zero-fetch/dist/index.js"></script>
Example
Performing a GET
request
// Make a request for a user with a given id // Optionally the request above could also be done asasync { try const data = await console catch error console }
Smart Request Body
If data
is a plain Javascript object, it will be encoded automatically and sent as search parameters, or request body, based on method
and requestType
.
Smart Search Parameters
When converting data
to search parameters, nested objects are encoded to be understanded by express
, so that req.query
is same as data
.
TODO: FormData application/x-www-form-urlencoded TODO: base64 encode inner Blob
data
: the data to be sent as search parameters(GET
) or the request body(other method).
Smart Response
Response body is automatically converted by proper method, based on Content-Type
of response header. Supported types are:
application/json
:.json
text/plain
:.text
application/octect-stream
:.blob