{"id":32275741,"url":"https://github.com/andreykedo/http_middleware","last_synced_at":"2025-10-22T23:54:36.012Z","repository":{"id":218520475,"uuid":"726884826","full_name":"AndreyKedo/http_middleware","owner":"AndreyKedo","description":"An Http client that uses middleware to handle requests.","archived":false,"fork":false,"pushed_at":"2025-09-15T06:30:45.000Z","size":77,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"dev","last_synced_at":"2025-10-22T23:54:35.113Z","etag":null,"topics":["dart","flutter-package","http-client","http-middleware"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/http_middleware_client","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AndreyKedo.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-12-03T17:27:03.000Z","updated_at":"2025-09-15T06:30:51.000Z","dependencies_parsed_at":"2024-01-22T14:46:39.750Z","dependency_job_id":"80eb2d06-3cc0-425f-8035-9235a81eda25","html_url":"https://github.com/AndreyKedo/http_middleware","commit_stats":null,"previous_names":["andreykedo/rest_client","andreykedo/restclient","andreykedo/http_middleware"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/AndreyKedo/http_middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreyKedo%2Fhttp_middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreyKedo%2Fhttp_middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreyKedo%2Fhttp_middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreyKedo%2Fhttp_middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AndreyKedo","download_url":"https://codeload.github.com/AndreyKedo/http_middleware/tar.gz/refs/heads/dev","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndreyKedo%2Fhttp_middleware/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280534673,"owners_count":26346714,"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","status":"online","status_checked_at":"2025-10-22T02:00:06.515Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["dart","flutter-package","http-client","http-middleware"],"created_at":"2025-10-22T23:54:32.835Z","updated_at":"2025-10-22T23:54:35.999Z","avatar_url":"https://github.com/AndreyKedo.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HttpMiddlewareClient\n\nAn wrapper around package [http](https://pub.dev/packages/http) HTTP client that \nsupports middleware for processing requests and responses.\n\nThis package provides an HTTP client that allows you to add middleware\nto process requests before they are sent and responses after they are received.\n\nMiddleware can be used for various purposes such as:\n- Adding authentication headers\n- Logging requests and responses\n- Handling errors globally\n- Modifying requests or responses\n\n## Features\n\n- Middleware support for request/response processing\n- Two types of middleware: inline and queued\n- Context passing between middlewares\n- Fully compatible with the http package\n\n## How use Middleware\n\nThere are two types of middleware:\n\n- **Middleware.inline** - Simple handler that processes requests asynchronously\n- **Middleware.inlineQueue** - Handler with execution queue for sequential processing\n\nMiddlewares are executed in the order they are added to the list. Each middleware must call handler(request, context) to pass control to the next handler.\n\n```dart\nimport 'package:http_middleware_client/http_middleware_client.dart';\n\n  final middlewares = [\n    Middleware.inline((request, context, handler) async {\n      // Handle request\n      request.headers['X-Custom-Header'] = 'value';\n\n      final result = await handler(request, context);\n\n      // Handle response\n      if(result.headers['X-Custom-Header-Result'] == 'true'){\n        notifyClients();\n      }\n\n      return result;\n    }),\n    \n    // Token refresh\n    Middleware.inlineQueue((request, context, handler) async {\n      final token = await fetchToken();\n      request.headers['Authorization'] = 'Bearer $token';\n      context['auth_token'] = token;\n      return handler(request, context);\n    })\n  ];\n\n  final client = HttpMiddlewareClient(middlewares: middlewares);\n  print(response.statusCode);\n  client.close();\n```\n\n## Custom Middleware Implementation\n\nYou can also create custom middleware by extending the Middleware class:\n\n```dart\nfinal class UserAgentMiddleware extends Middleware {\n  UserAgentMiddleware(this.source);\n\n  final UserAgentSource source;\n\n  @override\n  Handler call(Handler innerSend) {\n    Future\u003cStreamedResponse\u003e middleware(request, context) async {\n      final userAgent = await source.getUserAgent();\n      request.headers['User-agent'] = userAgent;\n      return handle(request, context, innerSend);\n    }\n\n    return middleware;\n  }\n\n}\n```\n\nOr extend QueueMiddleware for sequential processing:\n\n```dart\nclass AuthMiddleware extends QueueMiddleware {\n  @override\n  Future\u003cStreamedResponse\u003e handle(\n    BaseRequest request, \n    Map\u003cString, Object?\u003e context, \n    Handler handler,\n  ) async {\n    final token = await getAuthToken();\n    request.headers['Authorization'] = 'Bearer $token';\n    return handler(request, context);\n  }\n}\n```\n\n## Context Usage\n\nEach middleware can read/write data in the context (Map\u003cString, Object?\u003e), which is passed between handlers:\n\n```dart\nMiddleware.inline((request, context, handler) async {\n  // Write to context\n  context['start_time'] = DateTime.now();\n  \n  final response = await handler(request, context);\n  \n  // Read from context\n  final startTime = context['start_time'] as DateTime;\n  final duration = DateTime.now().difference(startTime);\n  print('Request took ${duration.inMilliseconds}ms');\n  \n  return response;\n});\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreykedo%2Fhttp_middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreykedo%2Fhttp_middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreykedo%2Fhttp_middleware/lists"}