From 8889dc038348c0109e086eb7fa1a007bb72d621f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?shravan=20=7C=7C=20=E0=A4=B6=E0=A5=8D=E0=A4=B0van?= Date: Fri, 31 Jan 2025 01:19:26 +0530 Subject: [PATCH] chore(docs): fix documentation for usage of interceptors in axios (#6116) chore(docs): fix documentation for usage of interceptors in axios (#6116) --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index addd098..189010b 100644 --- a/README.md +++ b/README.md @@ -719,8 +719,11 @@ instance.get('/longRequest', { You can intercept requests or responses before they are handled by `then` or `catch`. ```js + +const instance = axios.create(); + // Add a request interceptor -axios.interceptors.request.use(function (config) { +instance.interceptors.request.use(function (config) { // Do something before request is sent return config; }, function (error) { @@ -729,7 +732,7 @@ axios.interceptors.request.use(function (config) { }); // Add a response interceptor -axios.interceptors.response.use(function (response) { +instance.interceptors.response.use(function (response) { // Any status code that lie within the range of 2xx cause this function to trigger // Do something with response data return response; @@ -743,7 +746,8 @@ axios.interceptors.response.use(function (response) { If you need to remove an interceptor later you can. ```js -const myInterceptor = axios.interceptors.request.use(function () {/*...*/}); +const instance = axios.create(); +const myInterceptor = instance.interceptors.request.use(function () {/*...*/}); axios.interceptors.request.eject(myInterceptor); ```