How the HTTP Client works
Dio
library. It serves as a centralized system for managing HTTP requests and responses, streamlining network communication throughout the app. Below is an in-depth look at its functionality and extensibility.
HttpClient
class is responsible for setting up and configuring instances of the Dio
client. It defines common HTTP methods such as get
, post
, put
, and delete
, providing a unified interface for network operations. Its key features include:
UNAUTHORIZED
status, it attempts to refresh the token using HttpAuthClient
. If the token refresh is successful, the original request is retried with the new token.
_retryDio
, is used for retrying requests after a token refresh. This helps to avoid infinite loops in the case where a request continuously fails.
onRequest
interceptor. This ensures that the additional header is included in every HTTP request made through the client.
onRequest
>
interceptor, ensuring that all outgoing requests are authenticated without additional effort from the developer.
UNAUTHORIZED
responses. If a request fails due to an expired token, the client uses HttpAuthClient
to obtain a fresh token and retries the original request. This process is transparent to the rest of the application.