सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
एक डार्ट पैकेज जो HTTP कॉल के लिए आगमन और संशोधन की अनुमति देता है। यह लॉगिंग, प्रमाणीकरण हेडर और त्रुटि प्रबंधन जैसे क्रॉस-कटिंग चिंताओं को HTTP कॉल में जोड़ने का स्पष्ट तरीका प्रदान करता है। `http` पैकेज के साथ उपयोग के लिए बनाया गया है, जो विश्वसनीय अनुरोध/प्रतिक्रिया प्रक्रिया के लिए इंटरसेप्टर को श्रृंखला में जोड़ने की अनुमति देता है। डिबगिंग, सुरक्षा और Flutter ऐप में स्थिर API इंटरैक्शन बनाए रखने के लिए आदर्श है।
उपयोग
API रिक्वेस्ट लॉगिंग
प्रमाणीकरण हेडर इंजेक्शन
वैश्विक त्रुटि संभाल
अनुरोध/प्रतिक्रिया रूपांतरण
नेटवर्क कॉल्स का डीबगिंग
केंद्रीकृत HTTP तर्क
मुख्य विशेषताएँ
चेनेबल इंटरसेप्टर्स
अनुरोध/प्रतिक्रिया संशोधन
http पैकेज के साथ आसान एकीकरण
सिंक्रोनस और एसिंक्रोनस ऑपरेशन का समर्थन करता है
कस्टम लॉजिक के लिए विस्तार्य
क्रॉस-प्लेटफ़ॉर्म संगतता
इनके लिए उपयुक्त
केंद्रीय HTTP नियंत्रण की आवश्यकता वाले विकासकर्ता
सुरक्षित τोकन प्रबंधन की आवश्यकता वाले एप्स
पर्यवेक्षण और डिबगिंग पर केंद्रित टीमें
http पैकेज का व्यापक उपयोग करने वाले प्रोजेक्ट
जटिल API इंटरैक्शन पैटर्न वाले एप्लिकेशन
विचार योग्य बातें
इंटरसेप्टर पैटर्न की समझ आवश्यक है
सरल HTTP कॉल्स के लिए जटिलता बढ़ सकती है
असिंक्रोनस ऑपरेशन का सावधानी से प्रबंधन करने की आवश्यकता है
पूर्ण HTTP क्लाइंट के प्रतिस्थापन के रूप में नहीं
http पैकेज एकीकरण सीमित
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
HttpTools
A comprehensive collection of Dart and Flutter packages for HTTP request handling, providing intercepting, logging, and caching capabilities to enhance your network operations.
✅ Smart Binary Detection - Clean logs without garbage data
✅ Production Ready - Configurable for development vs production
✅ Human Readable - Clean, structured log format
Log Output Examples:
[a1b2c3d4] --> GET https://api.example.com/users/123
[a1b2c3d4] authorization: Bearer ***
[a1b2c3d4] content-type: application/json
[a1b2c3d4] --> END GET
[a1b2c3d4] <-- 200OK (145ms)
[a1b2c3d4] content-type: application/json
[a1b2c3d4] {"id": 123, "name": "John Doe"}
[a1b2c3d4] <-- END
Usage:
import'package:http_client_logger/http_client_logger.dart';
import'package:logging/logging.dart'hideLevel;
// Set up loggingLogger.root.onRecord.listen((record) => print(record.message));
// Configure loggerHttpClientProxy(
interceptors: [
HttpLogger(
level: Level.body, // basic | headers | body
logBodyContentTypes: {'application/json'}, // Only log JSON as text
),
],
)
http_client_cache
HTTP caching with disk/memory storage - Improve performance and reduce network usage
Key Features:
✅ RFC 7234 Compliant - Standard HTTP caching behavior
✅ Memory & Disk Storage - Choose what fits your needs
✅ Cache-Control Support - Respects server cache directives
✅ Stale-While-Revalidate - Serve stale content while updating
✅ Stale-If-Error - Fallback to cache when network fails
✅ Automatic Cleanup - LRU eviction and size limits
✅ Private Content Filtering - Secure handling of sensitive data
Cache Behavior Examples:
Cache miss for https://api.example.com/posts/1 # First requestCache hit for https://api.example.com/posts/1 # Served from cacheCache entry expired for https://api.example.com/posts/1 # Needs refreshServing stale content due to network error # Stale-if-error fallback
HttpClientProxy(
interceptors: [
if (kDebugMode) HttpLogger(level: Level.body), // Only log in debugAuthInterceptor(apiKey),
cache,
],
)
Custom Cache Control
classCacheControlInterceptorextendsHttpInterceptor{
@overrideFutureOr<OnResponse> onResponse(StreamedResponse response) {
final headers = Map<String, String>.from(response.headers);
// Cache API responses with resilience featuresif (response.request?.url.path.startsWith('/api/') ?? false) {
headers['cache-control'] =
'max-age=300, stale-while-revalidate=60, stale-if-error=3600';
// Cache for 5 min, serve stale for 1 min while revalidating,// serve stale for 1 hour if network fails
}
returnOnResponse.next(response.copyWith(headers: headers));
}
}
🔗 Framework Compatibility
Works seamlessly with popular HTTP packages:
✅ http - A composable, multi-platform, Future-based API for HTTP requests.
✅ chopper - An http client generator using source_gen, inspired by Retrofit
✅ retrofit - An dio client generator using source_gen and inspired by Chopper and Retrofit
Note:dio and retrofit (which uses dio) require the dio_compatibility_layer package to work with the standard http package that these interceptors depend on.
dependencies:http:^1.2.0dio_compatibility_layer:^3.0.0# Required for dio/retrofit compatibility
📊 Performance Considerations
Development vs Production:
HttpClientProxy(
interceptors: [
// Production: Only basic loggingif (kReleaseMode) HttpLogger(level: Level.basic),
// Development: Full logging with bodies if (kDebugMode) HttpLogger(level: Level.body),
// Always cache for better performance
cache,
],
)
Memory Management:
Cache automatically manages size with LRU eviction
Use cache.clearCache() when memory is low
Use cache.deletePrivateContent() when user logs out