Redux & Redux Toolkit
/Intermediate
fetchBaseQuery()
Definition
A lightweight wrapper around the native browser `fetch` API provided by RTK Query. It aims to simplify requests by providing sensible defaults like automatically parsing JSON.
Explain Like I'm New
It's RTK Query's built-in version of Axios. Instead of having to manually write `fetch().then(res => res.json())` a hundred times, `fetchBaseQuery` handles the JSON parsing and error throwing for you.
Real World Example
Using `fetchBaseQuery` to automatically attach a Bearer Token (JWT) to the `Authorization` header of every single outgoing API request.
Common Use Cases
- •Setting base URLs
- •Injecting authorization headers globally
Interactive Example
Loading...
Console output will appear here...
Interview Questions
basic
- Does `fetchBaseQuery` automatically convert JSON responses into JavaScript objects?
intermediate
- How do you attach a JWT token from your Redux store to every request using `fetchBaseQuery`?