Skip to content

Instantly share code, notes, and snippets.

@Nainik2509
Created November 9, 2023 13:05
Show Gist options
  • Save Nainik2509/2840600fe70066e7c887cb05838cf953 to your computer and use it in GitHub Desktop.
Save Nainik2509/2840600fe70066e7c887cb05838cf953 to your computer and use it in GitHub Desktop.
Axios Request Interceptor
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