Getting into it
You know that moment when your Angular app keeps calling an API, and the API is like nope, 401, who are you. That’s usually because the request didn’t bring an Authorization header. So instead of remembering to add headers in every single service call, I’d rather catch it once and fix it everywhere. That’s where an HTTP interceptor hits hard. It sits in the middle, grabs every outgoing request, and adds the token before it leaves.
At first it sounds scary, like you’re messing with all network calls at once. But it’s actually pretty clean if you keep it simple. You set up one interceptor, pull the token from wherever you store it, clone the request because requests are immutable, then attach Authorization: Bearer <token>. After that, most of your app just works without extra code sprinkled around.
Then yeah, edge cases show up fast. Like login calls that should not include a token yet. Or refresh token logic when a token expires mid request. Or skipping certain URLs like public endpoints and static assets. This is where you slow down for a second and decide rules so your interceptor doesn’t accidentally break stuff.
Quick wrap
The goal is simple. One place to add auth headers so every request is consistent, and you don’t forget anything when you build new features.