This snippet provides a convenient base API with some injected headers and operations that you can use in your apps.
Axios over Fetch API?
While Fetch API is a really decent choice, Axios provides a flexible configuration and more functionality with less code and a small bundle size therefore making it my choice of networking tool. Axios provides multiple features such as automatic response-to-JSON handling, better error messages and setting a response timeout without using an abort controller, just to mention a few.
Reminder
Be sure to never hardcore any private keys (e.g. API keys) and always serve them from somewhere safe - e.g. from .env
file during runtime.