Skip to content

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.

License

Notifications You must be signed in to change notification settings

flutter-news-app-full-source-code/http-client

Repository files navigation

Flutter News App Toolkit Logo

HTTP Client

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.

coverage: XX% Live Docs: View Main Project: Browse

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.

⭐ Feature Showcase: Streamlined & Secure API Communication

This package provides a comprehensive set of features for managing HTTP requests.

🧱 Core Functionality

🚀 Robust HttpClient

  • HttpClient Class: The main entry point for making HTTP requests, abstracting away dio complexities.
  • Simplified HTTP Methods: Provides get<T>(), post<T>(), put<T>(), and delete<T>() methods for common API interactions.

🔐 Automatic Authentication

  • AuthInterceptor: Automatically injects Authorization: Bearer <token> headers into requests.
  • Flexible TokenProvider: Retrieves authentication tokens via a configurable asynchronous function, allowing integration with various authentication mechanisms.

🛡️ Standardized Error Handling

  • ErrorInterceptor: Maps DioException types and non-2xx HTTP status codes to specific HttpException subtypes (e.g., NetworkException, BadRequestException, UnauthorizedException, NotFoundException, ServerException, UnknownException) defined in the core package. This ensures predictable and consistent error management across the application layers.

⚡ Performance & Control

  • Request Cancellation: Supports request cancellation using dio's CancelToken for improved resource management and user experience.
  • Configurable Timeouts: Allows configuration of connection, receive, and send timeouts for robust network operations.

🌐 Platform Adaptability

  • 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.

🔑 Licensing

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.

About

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.

Resources

License

Stars

Watchers

Forks

Languages