Created
November 9, 2023 13:05
-
-
Save Nainik2509/2840600fe70066e7c887cb05838cf953 to your computer and use it in GitHub Desktop.
Axios Request Interceptor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import axios from 'axios'; | |
| /* The code `axios.interceptors.request.use((config) => { ... })` is creating an interceptor for Axios | |
| requests. */ | |
| axios.interceptors.request.use((config) => { | |
| // Log to print that request is intiated.. | |
| console.log('Request was sent'); | |
| // Data that can be keep track of which are sent in request | |
| console.log(`[${config.method}] ${config.url}`); | |
| console.log(`Headers :`); | |
| console.log(config.headers); | |
| console.log(`Params : `); | |
| console.log(config.params); | |
| console.log(`Data : `); | |
| console.log(config.data); | |
| return config; | |
| }); | |
| const fetchQuotes = async () => { | |
| try { | |
| const res = await axios.get(`https://type.fit/api/quotes`); | |
| } catch (error) { | |
| console.log(error); | |
| } | |
| }; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment