{"id":19634647,"url":"https://github.com/tpal-dev/dio_clean_http_response","last_synced_at":"2025-04-28T07:31:48.013Z","repository":{"id":220790349,"uuid":"741310960","full_name":"tpal-dev/dio_clean_http_response","owner":"tpal-dev","description":"Dio Clean HTTP Response is a Dart package that simplifies handling HTTP responses when using the Dio library. It provides clean, structured, and customizable error handling for various HTTP failure scenarios.","archived":false,"fork":false,"pushed_at":"2024-06-09T16:08:52.000Z","size":30,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-08-04T09:27:17.700Z","etag":null,"topics":["dart","dio","flutter","http","pub-dev"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/dio_clean_http_response","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/tpal-dev.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":"2024-01-10T06:06:03.000Z","updated_at":"2024-06-09T16:08:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"2713fc3c-fa89-4f3d-947b-1ff0b22c67e4","html_url":"https://github.com/tpal-dev/dio_clean_http_response","commit_stats":null,"previous_names":["tpal-dev/dio_clean_http_response"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpal-dev%2Fdio_clean_http_response","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpal-dev%2Fdio_clean_http_response/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpal-dev%2Fdio_clean_http_response/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpal-dev%2Fdio_clean_http_response/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tpal-dev","download_url":"https://codeload.github.com/tpal-dev/dio_clean_http_response/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224100994,"owners_count":17255872,"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":["dart","dio","flutter","http","pub-dev"],"created_at":"2024-11-11T12:22:14.201Z","updated_at":"2024-11-11T12:22:15.156Z","avatar_url":"https://github.com/tpal-dev.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dio Clean HTTP Response\n\n[![Pub Version](https://img.shields.io/pub/v/dio_clean_http_response)](https://pub.dev/packages/dio_clean_http_response)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\n[Dio Clean HTTP Response](link_to_your_repo) is a Dart package that simplifies handling HTTP responses when using the Dio library. It provides clean, structured, and customizable error handling for various HTTP failure scenarios.\n\n## Index\n\n- [Motivation](#motivation)\n- [Features](#features)\n- [Usage](#usage)\n- [Installation](#installation)\n- [Either Type](#either-type)\n- [HttpFailure Class](#httpfailure-class)\n- [HttpFailuresLocalization Class](#httpfailureslocalization-class)\n- [Contributions](#contributions)\n- [License](#license)\n\n## Motivation\n\nDeveloping applications that interact with APIs often involves handling HTTP responses, including potential errors and data parsing. The Dio Clean HTTP Response package aims to simplify and streamline this process by providing an extension on `Future\u003cResponse\u003e`.\n\nThe motivation behind this package is to offer a clean and consistent way to convert Dio HTTP responses into either successful model instances or comprehensive error handling using HttpFailure sealed class and function programming pattern (Either type pattern) for Either monads as `Future\u003cEither\u003cHttpFailure, TModel\u003e\u003e` (`TModel` - generic type)\n\nKey Goals\n\n- Simplicity: Make the process of handling Dio HTTP responses straightforward and easy to implement.\n- Consistency: Ensure a consistent pattern for converting responses into either successful results or detailed failure instances.\n- Error Handling: Provide a robust mechanism for handling different HTTP failure scenarios with the HttpFailure class.\n\n## Features\n\n- **Clean API Integration:** Seamlessly integrate clean HTTP response handling into your Dio requests, making error management more robust and maintainable. (`Either` type pattern)\n\n- **Structured Error Handling:** Easily manage Dio Exceptions using a set of subtypes of `HttpFailure` sealed class, each representing a specific HTTP failure scenario.\n\n- **Localization Support:** Customize error messages for different scenarios with the ability to provide your own localization implementation.\n\n## Usage\n\n```dart\nimport 'package:dio/dio.dart';\nimport 'package:dio_clean_http_response/src/dio_clean_http_response_extension.dart';\n\nclass PostModel {\n  final int id;\n  final int userId;\n  final String title;\n  final String body;\n\n  const PostModel({\n    required this.id,\n    required this.userId,\n    required this.title,\n    required this.body,\n  });\n\n  factory PostModel.fromJson(Map\u003cString, dynamic\u003e json) {\n    return PostModel(\n      id: json[\"id\"] as int,\n      userId: json[\"userId\"] as int,\n      title: json[\"title\"] as String,\n      body: json[\"body\"] as String,\n    );\n  }\n\n  @override\n  String toString() =\u003e '🟩\\nPOST $id \\nuserId: $userId \\ntitle: $title \\nbody:$body\\n';\n}\n\nvoid main() async {\n  final httpClient = Dio(\n    BaseOptions(\n      baseUrl: 'https://jsonplaceholder.typicode.com',\n    ),\n  );\n\n  final postModelOrFailure = await httpClient.get('/posts/1').fromJson(PostModel.fromJson);\n\n  postModelOrFailure.fold(\n    (failure) =\u003e print(failure.message()),\n    (postModel) =\u003e print(postModel),\n  );\n\n  final postModelsListOrFailure = await httpClient.get('/posts').fromJsonAsList(PostModel.fromJson);\n\n  postModelsListOrFailure.fold(\n    (failure) =\u003e print(failure.message()),\n    (postModelsList) =\u003e print(postModelsList),\n  );\n}\n\n\n```\n\n### Installation\n\nAdd the following to your `pubspec.yaml` file:\n\n```yaml\ndependencies:\n  dio_clean_http_response: ^2.0.0\n  dio: ^5.4.0\n```\n\nThen run:\n\n```bash\npub get\n```\n\n## Either Type\n\nFunctional Error Handling `Either` is an alternative to Nullable value and Exceptions. More info about either https://pub.dev/packages/either_dart | https://pub.dev/packages/either_dart\n\n## HttpFailure Sealed class\n\nThe `HttpFailure` sealed class represents a set of subtypes covering all Dio Exceptions for different HTTP failure scenarios. More info about sealed class https://dart.dev/language/class-modifiers#sealed\n\n## HttpFailuresLocalization Class\n\nThe `HttpFailuresLocalization` abstract class defining a contract for providing localized error messages for different HTTP failure scenarios. Implementations should define getters to retrieve localized error messages for each scenario.\n\nThe `HttpFailuresLocalizationDefaultImpl` class provides default localized error messages for different HTTP failure scenarios.\n\n## Contributions\n\nWe welcome contributions! If you find a bug or have a feature request, please open an issue. Pull requests are also appreciated.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftpal-dev%2Fdio_clean_http_response","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftpal-dev%2Fdio_clean_http_response","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftpal-dev%2Fdio_clean_http_response/lists"}