Fetchum is a simplified api for making xhr requests. It is a wrapper around the native fetch api implemented in new browsers and has the most well know polyfill for fetch as the fallback for older browsers.
It also allows you to build a request function to call later describing how a call will be made
using the generateRequest
function. This allows for very descriptive usage of a api and increases readability
of how requests are made overall.
Example:
const getUser = generateRequest({
token: true,
method: 'GET',
route: '/v1/users/:id',
});
getUser({id: 1})
.then((res) => { setUser(res.user); })
.catch((res) => { setErrors(res.errors); });
By the example here we are able to describe how a api is used and even say that we have a token in localstorage that will be passed in an authorization header with that token for you. There are many other convenience options that are also available to make describing how a endpoint is used concise, easy and reuseable.