{"id":24502656,"url":"https://github.com/ralph-bergmann/httptools","last_synced_at":"2026-03-04T23:01:39.849Z","repository":{"id":246603743,"uuid":"821610471","full_name":"ralph-bergmann/HttpTools","owner":"ralph-bergmann","description":"collection of Dart and Flutter libraries for HTTP request handling","archived":false,"fork":false,"pushed_at":"2025-10-06T10:47:38.000Z","size":278,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-19T10:14:59.609Z","etag":null,"topics":["cache","dart","flutter","http","interceptor","network"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ralph-bergmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-06-29T00:28:22.000Z","updated_at":"2025-10-06T10:47:42.000Z","dependencies_parsed_at":"2024-06-29T01:51:04.340Z","dependency_job_id":"7eb0af79-f76d-4926-99a5-618b1073d8a2","html_url":"https://github.com/ralph-bergmann/HttpTools","commit_stats":null,"previous_names":["ralph-bergmann/httptools"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/ralph-bergmann/HttpTools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralph-bergmann%2FHttpTools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralph-bergmann%2FHttpTools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralph-bergmann%2FHttpTools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralph-bergmann%2FHttpTools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ralph-bergmann","download_url":"https://codeload.github.com/ralph-bergmann/HttpTools/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralph-bergmann%2FHttpTools/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30098085,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T22:49:54.894Z","status":"ssl_error","status_checked_at":"2026-03-04T22:49:48.883Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","dart","flutter","http","interceptor","network"],"created_at":"2025-01-21T23:13:14.177Z","updated_at":"2026-03-04T23:01:39.844Z","avatar_url":"https://github.com/ralph-bergmann.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HttpTools\n\nA comprehensive collection of Dart and Flutter packages for HTTP request handling, providing intercepting, logging, and caching capabilities to enhance your network operations.\n\n## 📦 Packages Overview\n\n| Package | Version | Description |\n|---------|---------|-------------|\n| [`http_client_interceptor`](https://pub.dev/packages/http_client_interceptor) | [![pub package](https://img.shields.io/pub/v/http_client_interceptor.svg)](https://pub.dev/packages/http_client_interceptor) | Core HTTP interceptor framework |\n| [`http_client_logger`](https://pub.dev/packages/http_client_logger) | [![pub package](https://img.shields.io/pub/v/http_client_logger.svg)](https://pub.dev/packages/http_client_logger) | Comprehensive HTTP request/response logging |\n| [`http_client_cache`](https://pub.dev/packages/http_client_cache) | [![pub package](https://img.shields.io/pub/v/http_client_cache.svg)](https://pub.dev/packages/http_client_cache) | HTTP caching with disk/memory storage |\n\n## 🚀 Quick Start\n\n### Installation\n\nAdd any or all packages to your `pubspec.yaml`:\n\n```yaml\ndependencies:\n  http_client_interceptor: ^1.0.1\n  http_client_logger: ^1.1.2\n  http_client_cache: ^1.0.3\n```\n\n### Basic Usage - All Features Combined\n\n```dart\nimport 'dart:async';\nimport 'dart:io';\nimport 'package:http/http.dart' as http;\nimport 'package:http_client_interceptor/http_client_interceptor.dart';\nimport 'package:http_client_logger/http_client_logger.dart';\nimport 'package:http_client_cache/http_client_cache.dart';\nimport 'package:logging/logging.dart' hide Level;\n\nFuture\u003cvoid\u003e main() async {\n  // Enable logging to see what's happening\n  Logger.root.onRecord.listen((record) {\n    print('[${record.level.name}] ${record.message}');\n  });\n\n  // Initialize cache\n  final cache = HttpCache();\n  await cache.initInMemory(); // or initLocal(Directory) for persistent cache\n\n  // Configure HTTP client with all interceptors\n  await http.runWithClient(\n    () async {\n      final client = http.Client();\n      \n      // Make requests - they'll be logged and cached automatically\n      final response1 = await client.get(\n        Uri.parse('https://jsonplaceholder.typicode.com/posts/1')\n      );\n      print('First request: ${response1.statusCode}');\n      \n      // Second identical request will be served from cache\n      final response2 = await client.get(\n        Uri.parse('https://jsonplaceholder.typicode.com/posts/1')\n      );\n      print('Second request: ${response2.statusCode}');\n      \n      client.close();\n    },\n    () =\u003e HttpClientProxy(\n      interceptors: [\n        HttpLogger(level: Level.headers), // Log requests/responses\n        cache, // Cache responses\n      ],\n    ),\n  );\n}\n```\n\n## 📋 Detailed Package Documentation\n\n### http_client_interceptor\n\n**Core HTTP interceptor framework** - Foundation for all other packages\n\n**Key Features:**\n- ✅ Intercept HTTP requests and responses\n- ✅ Modify headers, body, and URLs\n- ✅ Handle errors and retries\n- ✅ Chain multiple interceptors\n- ✅ Compatible with all popular HTTP packages\n\n**Simple Custom Interceptor:**\n\n```dart\nimport 'package:http_client_interceptor/http_client_interceptor.dart';\n\nclass AuthInterceptor extends HttpInterceptor {\n  final String apiKey;\n  AuthInterceptor(this.apiKey);\n\n  @override\n  FutureOr\u003cOnRequest\u003e onRequest(BaseRequest request) {\n    // Add API key to all requests\n    request.headers['Authorization'] = 'Bearer $apiKey';\n    return OnRequest.next(request);\n  }\n\n  @override\n  FutureOr\u003cOnResponse\u003e onResponse(StreamedResponse response) {\n    print('Response: ${response.statusCode} for ${response.request?.url}');\n    return OnResponse.next(response);\n  }\n\n  @override\n  FutureOr\u003cOnError\u003e onError(BaseRequest request, Object error, StackTrace? stackTrace) {\n    print('Request failed: ${request.url} - Error: $error');\n    return OnError.next(request, error, stackTrace);\n  }\n}\n```\n\n### http_client_logger\n\n**Comprehensive HTTP logging** - See exactly what your app is sending and receiving\n\n**Key Features:**\n- ✅ **Unique Request IDs** - Track concurrent requests easily\n- ✅ **Multiple Log Levels** - `basic`, `headers`, `body` \n- ✅ **Smart Binary Detection** - Clean logs without garbage data\n- ✅ **Production Ready** - Configurable for development vs production\n- ✅ **Human Readable** - Clean, structured log format\n\n**Log Output Examples:**\n```\n[a1b2c3d4] --\u003e GET https://api.example.com/users/123\n[a1b2c3d4]     authorization: Bearer ***\n[a1b2c3d4]     content-type: application/json\n[a1b2c3d4] --\u003e END GET\n[a1b2c3d4] \u003c-- 200 OK (145ms)\n[a1b2c3d4]     content-type: application/json\n[a1b2c3d4]     {\"id\": 123, \"name\": \"John Doe\"}\n[a1b2c3d4] \u003c-- END\n```\n\n**Usage:**\n```dart\nimport 'package:http_client_logger/http_client_logger.dart';\nimport 'package:logging/logging.dart' hide Level;\n\n// Set up logging\nLogger.root.onRecord.listen((record) =\u003e print(record.message));\n\n// Configure logger\nHttpClientProxy(\n  interceptors: [\n    HttpLogger(\n      level: Level.body, // basic | headers | body\n      logBodyContentTypes: {'application/json'}, // Only log JSON as text\n    ),\n  ],\n)\n```\n\n### http_client_cache\n\n**HTTP caching with disk/memory storage** - Improve performance and reduce network usage\n\n**Key Features:**\n- ✅ **RFC 7234 Compliant** - Standard HTTP caching behavior\n- ✅ **Memory \u0026 Disk Storage** - Choose what fits your needs\n- ✅ **Cache-Control Support** - Respects server cache directives\n- ✅ **Stale-While-Revalidate** - Serve stale content while updating\n- ✅ **Stale-If-Error** - Fallback to cache when network fails\n- ✅ **Automatic Cleanup** - LRU eviction and size limits\n- ✅ **Private Content Filtering** - Secure handling of sensitive data\n\n**Cache Behavior Examples:**\n```\nCache miss for https://api.example.com/posts/1      # First request\nCache hit for https://api.example.com/posts/1       # Served from cache\nCache entry expired for https://api.example.com/posts/1  # Needs refresh\nServing stale content due to network error           # Stale-if-error fallback\n```\n\n**Usage:**\n```dart\nimport 'package:http_client_cache/http_client_cache.dart';\n\nFuture\u003cvoid\u003e setupCache() async {\n  final cache = HttpCache();\n  \n  // Option 1: Memory cache (faster, doesn't persist)\n  await cache.initInMemory(maxCacheSize: 50 * 1024 * 1024); // 50MB\n  \n  // Option 2: Disk cache (persists between app restarts)\n  // final cacheDir = Directory('cache');\n  // await cache.initLocal(cacheDir, maxCacheSize: 100 * 1024 * 1024);\n\n  return HttpClientProxy(interceptors: [cache]);\n}\n```\n\n## 🔧 Advanced Usage Patterns\n\n### Conditional Interceptors\n```dart\nHttpClientProxy(\n  interceptors: [\n    if (kDebugMode) HttpLogger(level: Level.body), // Only log in debug\n    AuthInterceptor(apiKey),\n    cache,\n  ],\n)\n```\n\n### Custom Cache Control\n```dart\nclass CacheControlInterceptor extends HttpInterceptor {\n  @override\n  FutureOr\u003cOnResponse\u003e onResponse(StreamedResponse response) {\n    final headers = Map\u003cString, String\u003e.from(response.headers);\n    \n    // Cache API responses with resilience features\n    if (response.request?.url.path.startsWith('/api/') ?? false) {\n      headers['cache-control'] = \n        'max-age=300, stale-while-revalidate=60, stale-if-error=3600';\n      // Cache for 5 min, serve stale for 1 min while revalidating,\n      // serve stale for 1 hour if network fails\n    }\n    \n    return OnResponse.next(response.copyWith(headers: headers));\n  }\n}\n```\n\n## 🔗 Framework Compatibility\n\nWorks seamlessly with popular HTTP packages:\n\n- ✅ [`http`](https://pub.dev/packages/http) - A composable, multi-platform, Future-based API for HTTP requests.\n- ✅ [`chopper`](https://pub.dev/packages/chopper) - An http client generator using source_gen, inspired by Retrofit \n- ✅ [`retrofit`](https://pub.dev/packages/retrofit) - An dio client generator using source_gen and inspired by Chopper and Retrofit\n- ✅ [`dio`](https://pub.dev/packages/dio) - A powerful HTTP networking package\n\n**Note:** `dio` and `retrofit` (which uses `dio`) require the [`dio_compatibility_layer`](https://pub.dev/packages/dio_compatibility_layer) package to work with the standard `http` package that these interceptors depend on.\n\n```yaml\ndependencies:\n  http: ^1.2.0\n  dio_compatibility_layer: ^3.0.0  # Required for dio/retrofit compatibility\n```\n\n## 📊 Performance Considerations\n\n**Development vs Production:**\n```dart\nHttpClientProxy(\n  interceptors: [\n    // Production: Only basic logging\n    if (kReleaseMode) HttpLogger(level: Level.basic),\n    \n    // Development: Full logging with bodies  \n    if (kDebugMode) HttpLogger(level: Level.body),\n    \n    // Always cache for better performance\n    cache,\n  ],\n)\n```\n\n**Memory Management:**\n- Cache automatically manages size with LRU eviction\n- Use `cache.clearCache()` when memory is low\n- Use `cache.deletePrivateContent()` when user logs out\n\n## 🐛 Debugging Tips\n\n**Enable verbose logging:**\n```dart\nLogger.root.level = Level.ALL;\nLogger.root.onRecord.listen((record) {\n  print('[${record.time}] ${record.level.name}: ${record.message}');\n  if (record.error != null) print('Error: ${record.error}');\n  if (record.stackTrace != null) print('Stack: ${record.stackTrace}');\n});\n```\n\n**Check cache status:**\n```dart\n// Look for Cache-Status headers in responses\nfinal cacheStatus = response.headers['cache-status'];\nprint('Cache status: $cacheStatus');\n```\n\n## 🤝 Contributing\n\nFound a bug or want to contribute? Check our [GitHub repository](https://github.com/ralph-bergmann/HttpTools) for:\n\n- 🐛 [Bug Reports](https://github.com/ralph-bergmann/HttpTools/issues)\n- 💡 [Feature Requests](https://github.com/ralph-bergmann/HttpTools/issues)\n- 🔀 [Pull Requests](https://github.com/ralph-bergmann/HttpTools/pulls)\n\n## 📄 License\n\nThis project is licensed under the MIT License - see individual package licenses for details.\n\n---\n\n**Need help?** Check out the individual package documentation or [open an issue](https://github.com/ralph-bergmann/HttpTools/issues) on GitHub!\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fralph-bergmann%2Fhttptools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fralph-bergmann%2Fhttptools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fralph-bergmann%2Fhttptools/lists"}