From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Setting up Axios interceptors

Setting up Axios interceptors

Welcome back. In the last video, we set up the exuse client, which was a generic client and underlying it was using exuse. We saw that using the create function, we can have the base URL property, the default headers, as well as some other properties like timeout. So this is where exuse is advanced from Fetch API. You can define a timeout of the request that if you didn't get a response for this number of milliseconds, then your request will automatically be timed out. Now we are going to see that along with every exeuse request, if we need to pass on any of the headers, so how can we do that in the client? So we don't have to do this in each of the API call. We can do something like exeos dot sorry the client dot interceptors dot request dot use. This is a middleware and a middleware is something that gets to catch the request or response before it actually gets processed. So before sending off this request, the client will be created and whatever headers we are going to write inside…

Contents