DEV Community

Cover image for Let's understand and make our API requests professional with HTTPInterceptor like a Pro

Let's understand and make our API requests professional with HTTPInterceptor like a Pro

Renan Ferro on January 08, 2024

Hey guys, how are you today?! It's 2024, let's make this year wonderful and do a lot of some cool things! Today I'd like to share and talk about ...
Collapse
 
guilhermemgbr profile image
GuilhermeMGBR

An alternative to cloning the request would be using an HttpClientFactory with the API URL as an argument. It was interesting seeing an example with HttpInterceptor though!

Collapse
 
renancferro profile image
Renan Ferro

Wow, the way you commented too is very interesting! I'll try to understand better and apply it to have another way! Thanks ✌️

Collapse
 
jangelodev profile image
João Angelo

Renan Ferro,
Great article !
Thanks for sharing...

Collapse
 
renancferro profile image
Renan Ferro

Muito obrigado João, fico feliz que tenha gostado 😄

Collapse
 
wellington1993 profile image
Wellington Torrejais da Silva

Nice idea of use the base URL constant inside the Interceptor!

Collapse
 
renancferro profile image
Renan Ferro

Eaee man

Bem legal né?! Facilita bastante 😆

Collapse
 
prog_25 profile image
prog-24

Haha, interceptors are really great, once you wrap your head around them, you can begin to appreciate the design pattern.

Collapse
 
renancferro profile image
Renan Ferro

Yes, things get more interesting each time 🤣

Collapse
 
makdeniss profile image
Deniss M

Still thinking their environment files are good for this. If you need to change the baseUrl -> just change the value (per env). Interceptors I would use for something like tokens or something like that. This we don't need to have in services, but we can inject this type of stuff in the interceptors.

Some comments have been hidden by the post's author - find out more