A robust and reusable Dart HTTP client built on top of the `dio` package, serving as a crucial abstraction layer within the Flutter News App Full Source Code Toolkit.
This http_client package serves as the foundational HTTP client for the Flutter News App Full Source Code Toolkit. Built on top of the dio package, it simplifies API interactions by providing common HTTP methods, automatic authentication header injection, and mapping network/status code errors to specific custom exceptions. It ensures consistent and robust communication with backend services across the Flutter mobile app, web dashboard, and Dart Frog backend API.
This package provides a comprehensive set of features for managing HTTP requests.
🧱 Core Functionality
HttpClientClass: The main entry point for making HTTP requests, abstracting awaydiocomplexities.- Simplified HTTP Methods: Provides
get<T>(),post<T>(),put<T>(), anddelete<T>()methods for common API interactions.
AuthInterceptor: Automatically injectsAuthorization: Bearer <token>headers into requests.- Flexible
TokenProvider: Retrieves authentication tokens via a configurable asynchronous function, allowing integration with various authentication mechanisms.
ErrorInterceptor: MapsDioExceptiontypes and non-2xx HTTP status codes to specificHttpExceptionsubtypes (e.g.,NetworkException,BadRequestException,UnauthorizedException,NotFoundException,ServerException,UnknownException) defined in thecorepackage. This ensures predictable and consistent error management across the application layers.
- Request Cancellation: Supports request cancellation using
dio'sCancelTokenfor improved resource management and user experience. - Configurable Timeouts: Allows configuration of connection, receive, and send timeouts for robust network operations.
BrowserHttpClientAdapter&IOHttpClientAdapter: Automatically selects the appropriate HTTP client adapter for web and non-web platforms, ensuring seamless operation across different environments.
💡 Your Advantage: You get a meticulously designed, production-quality HTTP client that simplifies API interactions, ensures secure authentication, provides robust error handling, and adapts to different platforms. This package accelerates development by providing a solid foundation for network communication.
This http_client package is an integral part of the Flutter News App Full Source Code Toolkit. For comprehensive details regarding licensing, including trial and commercial options for the entire toolkit, please refer to the main toolkit organization page.