In this tutorial, we'll learn how to set Up Axios interceptors for All HTTP Calls In an Application.
As the Internet gets more mature and sophisticated, gathering the data to do those complex things gets more complicated too.
Think about it: at the advent of the Internet you could send and receive email, search by keywords for information and visit a few, extremely basic websites. Today, you can: order a car and have it pick you up at your exact location within minutes, make purchases with a credit card number stored on your phone, search for extremely specific questions via voice and get thousands of useful, relevant answers. It’s amazing what’s at our fingertips now with very little effort on our part.
And as the Internet has grown more useful to us as users, it’s also grown more complex for us as developers to get the all the data needed to be so helpful, which is where my story today begins.
As a software engineer, the vast majority of the data I work with lives somewhere besides my application and the databases my team is responsible for. So I spend a lot of time requesting data, receiving data, validating data, reshaping data — all via HTTP calls to applications beyond my own.
A lot of the time, those HTTP calls aren’t so simple either: I can’t just send a
GET or a
POST and expect a 200 response. These HTTP calls need cookies, authorization tokens, secured headers, JWTs, API keys or other methods of verification — the teams I’m requesting that data from need to know my application is allowed to interact with the information they’re responsible for.
And that’s totally valid and very normal nowadays; systems need to prove they’re allowed to see or change data. It can’t just available for anyone with an Internet connection who knows the URL to their service, that could be very dangerous.