Introduction

Introduction

CallApi is an extra-lightweight wrapper around the Fetch API, designed to simplify making HTTP requests. It allows you to use familiar Fetch API syntax while offering additional options for convenience.

Just like Fetch, it takes a url and a request options object, but with added functionality to streamline common tasks. Check out the API Reference for a detailed look at each option.

With CallApi, handling responses is effortless. Instead of manually parsing the response, you can destructure both data and error in a single step, making your code cleaner and more efficient:

const { data, error } = await callApi("url", fetchOptions);

You can still pass the same request options as you would with Fetch API, ensuring compatibility with your existing code. Additionally, if you need access to the full response, it's available too:

const { data, error, response } = await callApi("url", fetchOptions);

Acknowledgements

Special thanks go to ofetch by unjs (opens in a new tab) for inspiring some of the features in the library, such as the function-based interceptors and retries. Also, credit goes to the zl-fetch fetch wrapper (opens in a new tab) for inspiring a few features in this library.