README.md

better-fetch

A tiny ES6 fetch() wrapper that makes your life easier.

Without changing the API, better-fetch automatically includes cookies, which would have saved me a very frustrating amount of time yesterday, lets you add default headers, and you can pass request body as a plain JS object, none of that FormData nonsense.

better-fetch works the same as fetch(), but is less cumbersome to use.

In practice better-fetch looks like this:

You install with npm. Or whatever you use to install packages from npmjs.org. Yarn maybe?

$ npm install --save better-fetch

Then you set up headers that every one of your fetch() calls needs. My backend requires an Authorization, and an Accept header from all calls.

A dictionary body is automatically transformed into a FormData object, strings and FormData objects are let through. This gives you flexibility to work with any API backend, but still makes your life easier.

Similarly, you can specify headers as either a Headers object or a dictionary - better-fetch has you covered.