{"id":17238380,"url":"https://github.com/hoc081098/http_client_hoc081098","last_synced_at":"2025-04-14T02:30:06.924Z","repository":{"id":64291168,"uuid":"531155346","full_name":"hoc081098/http_client_hoc081098","owner":"hoc081098","description":"Simple and powerful HTTP client for Flutter and Dart application, built on top of http, rxdart_ext and cancellation_token_hoc081098 packages.","archived":false,"fork":false,"pushed_at":"2025-02-27T00:37:24.000Z","size":96,"stargazers_count":3,"open_issues_count":5,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T02:29:46.423Z","etag":null,"topics":["dio-flutter","dio-interceptor","flutter-dio","flutter-http","flutter-http-client","http","http-client"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/http_client_hoc081098","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/hoc081098.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2022-08-31T15:55:52.000Z","updated_at":"2024-10-27T11:17:18.000Z","dependencies_parsed_at":"2024-10-24T13:14:36.010Z","dependency_job_id":"e01c059f-d729-48b1-85fb-c1fcdb34d256","html_url":"https://github.com/hoc081098/http_client_hoc081098","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoc081098%2Fhttp_client_hoc081098","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoc081098%2Fhttp_client_hoc081098/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoc081098%2Fhttp_client_hoc081098/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoc081098%2Fhttp_client_hoc081098/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoc081098","download_url":"https://codeload.github.com/hoc081098/http_client_hoc081098/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248810864,"owners_count":21165189,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["dio-flutter","dio-interceptor","flutter-dio","flutter-http","flutter-http-client","http","http-client"],"created_at":"2024-10-15T05:45:28.345Z","updated_at":"2025-04-14T02:30:06.899Z","avatar_url":"https://github.com/hoc081098.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# http_client_hoc081098\n\nSimple and powerful HTTP client for Flutter and Dart application.\n\n[![codecov](https://codecov.io/gh/hoc081098/http_client_hoc081098/graph/badge.svg?token=TNspe4aF8b)](https://codecov.io/gh/hoc081098/http_client_hoc081098)\n[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fhoc081098%2Fhttp_client_hoc081098\u0026count_bg=%239858E5\u0026title_bg=%23555555\u0026icon=\u0026icon_color=%23E7E7E7\u0026title=hits\u0026edge_flat=false)](https://hits.seeyoufarm.com)\n\n```dart\nimport 'dart:io';\n\nimport 'package:http/http.dart' as http;\nimport 'package:http/retry.dart' as http_retry;\nimport 'package:http_client_hoc081098/http_client_hoc081098.dart';\n\nimport 'user.dart';\n\nvoid main() async {\n  final loggingInterceptor = SimpleLoggingInterceptor(\n    SimpleLogger(\n      level: SimpleLogLevel.body,\n      headersToRedact: {\n        HttpHeaders.authorizationHeader,\n      },\n    ),\n  );\n\n  final innerClient = http_retry.RetryClient(\n    http.Client(),\n    retries: 3,\n    when: (response) {\n      print(\n          '[RetryClient] Checking response: request=${response.request} statusCode=${response.statusCode}');\n      print('-' * 128);\n      return response.statusCode == HttpStatus.unauthorized;\n    },\n    onRetry: (request, response, retryCount) async {\n      print(\n          '[RetryClient] Retrying request: request=$request, response=$response, retryCount=$retryCount');\n      // Simulate refreshing token\n      await Future\u003cvoid\u003e.delayed(const Duration(seconds: 1));\n      print('-' * 128);\n    },\n  );\n\n  final client = SimpleHttpClient(\n    client: innerClient,\n    timeout: const Duration(seconds: 10),\n    requestInterceptors: [\n      (request) async {\n        print('[requestInterceptors] request=$request');\n        await Future\u003cvoid\u003e.delayed(const Duration(milliseconds: 100));\n\n        final token = 'hoc081098';\n        request.headers[HttpHeaders.authorizationHeader] = 'Bearer $token';\n\n        return request;\n      },\n      loggingInterceptor.requestInterceptor,\n    ],\n    responseInterceptors: [\n      loggingInterceptor.responseInterceptor,\n    ],\n  );\n\n  await getExample(client);\n  print('-' * 128);\n\n  await getSingleExample(client);\n  print('-' * 128);\n\n  await postExample(client);\n  print('-' * 128);\n\n  client.close();\n  print('Client closed gratefully.');\n}\n\nFuture\u003cvoid\u003e postExample(SimpleHttpClient client) async {\n  try {\n    final json = await client.postJson(\n      Uri.parse('https://jsonplaceholder.typicode.com/users'),\n      body: {\n        'name': 'hoc081098',\n        'username': 'hoc081098',\n        'email': 'hoc081098@gmail.com',\n      },\n    ) as Map\u003cString, dynamic\u003e;\n    print(json);\n  } catch (e) {\n    print(e);\n  }\n}\n\nFuture\u003cvoid\u003e getSingleExample(SimpleHttpClient client) async {\n  final single = useCancellationToken\u003cdynamic\u003e(\n    (cancelToken) =\u003e client.getJson(\n      Uri.parse('https://jsonplaceholder.typicode.com/users/2'),\n      headers: {},\n      cancelToken: cancelToken,\n    ),\n  ).cast\u003cMap\u003cString, dynamic\u003e\u003e().map(User.fromJson);\n  final subscription = single.listen(print, onError: print);\n\n  () async {\n    await Future\u003cvoid\u003e.delayed(const Duration(milliseconds: 120));\n    await subscription.cancel();\n    print('Cancelling single...');\n  }()\n      .ignore();\n\n  await Future\u003cvoid\u003e.delayed(const Duration(seconds: 1));\n}\n\nFuture\u003cvoid\u003e getExample(SimpleHttpClient client) async {\n  final cancelToken = CancellationToken();\n  final uri = Uri.parse('https://jsonplaceholder.typicode.com/users/1');\n\n  () async {\n    await Future\u003cvoid\u003e.delayed(const Duration(milliseconds: 300));\n    cancelToken.cancel();\n    print('Cancelling...');\n  }()\n      .ignore();\n\n  try {\n    final json = await client.getJson(\n      uri,\n      headers: {},\n      cancelToken: cancelToken,\n    ) as Map\u003cString, dynamic\u003e;\n    print(json);\n  } catch (e) {\n    print(e);\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoc081098%2Fhttp_client_hoc081098","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoc081098%2Fhttp_client_hoc081098","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoc081098%2Fhttp_client_hoc081098/lists"}