{"id":18938852,"url":"https://github.com/nikoo-asadnejad/responsebase","last_synced_at":"2026-01-31T20:03:44.357Z","repository":{"id":157128987,"uuid":"630366204","full_name":"Nikoo-Asadnejad/ResponseBase","owner":"Nikoo-Asadnejad","description":"ResponseBase is a return type of a service or api which can be implicitly converted to objectResult","archived":false,"fork":false,"pushed_at":"2024-09-12T18:18:01.000Z","size":95,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-21T20:03:33.552Z","etag":null,"topics":["api","csharp","csharp-code","dotenetcore","dotnet","dotnet-core","response","response-management","rest-api","restful-api","result-pattern","result-type","resultbuilder","resultpattern"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nikoo-Asadnejad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-04-20T08:22:33.000Z","updated_at":"2025-06-11T16:40:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"5657f69b-fec9-4f80-a848-e68237fe820a","html_url":"https://github.com/Nikoo-Asadnejad/ResponseBase","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Nikoo-Asadnejad/ResponseBase","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikoo-Asadnejad%2FResponseBase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikoo-Asadnejad%2FResponseBase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikoo-Asadnejad%2FResponseBase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikoo-Asadnejad%2FResponseBase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nikoo-Asadnejad","download_url":"https://codeload.github.com/Nikoo-Asadnejad/ResponseBase/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nikoo-Asadnejad%2FResponseBase/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28952581,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T18:30:42.805Z","status":"ssl_error","status_checked_at":"2026-01-31T18:30:19.593Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["api","csharp","csharp-code","dotenetcore","dotnet","dotnet-core","response","response-management","rest-api","restful-api","result-pattern","result-type","resultbuilder","resultpattern"],"created_at":"2024-11-08T12:15:37.612Z","updated_at":"2026-01-31T20:03:44.333Z","avatar_url":"https://github.com/Nikoo-Asadnejad.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ResponseBase Pattern in C#\n\n`ResponseBase` is a generic return type designed for use in services or APIs. It standardizes the way responses are handled, encapsulating key elements of the response in a structured format that improves readability, maintainability, and usability across the application.\n\n## Features of ResponseBase\n\nThe `ResponseBase` class includes the following components:\n\n- **Status**: Represents the status of the operation, typically indicating success, failure, or any other defined state.\n- **Message**: Provides additional context or information about the operation, such as error messages or success confirmations.\n- **Data**: Contains the payload of the response, allowing any type of data to be returned (generic type `T`).\n\n## Implicit Conversions\n\n`ResponseBase` is designed with flexibility in mind, allowing implicit conversions between various types:\n\n1. **Conversion to ObjectResult**: `ResponseBase` can be implicitly converted to an `ObjectResult`, making it easy to return standardized responses from API controllers in ASP.NET Core.\n   \n2. **Conversion to HttpStatusCodes**: `ResponseBase` can also be implicitly converted to HTTP status codes, simplifying the mapping between service results and HTTP responses.\n\n3. **Conversion from HttpStatusCodes and Tuples**: Both HTTP status codes and tuples can be implicitly converted to `ResponseBase`. This allows you to quickly create `ResponseBase` instances from common status codes or value tuples, making the API easier to use and reducing boilerplate code.\n\n## Benefits of Using ResponseBase\n\n- **Consistency**: By using `ResponseBase`, all services and APIs return responses in a consistent format, making it easier to handle responses across the application.\n  \n- **Readability**: The structure of `ResponseBase` makes it clear what the status of a response is, what message (if any) accompanies it, and what data is being returned.\n  \n- **Error Handling**: Centralizes error handling by encapsulating errors within the `Status` and `Message` fields, providing a clear and uniform way to handle exceptions and errors.\n\n- **Extensibility**: The generic type parameter `T` allows `ResponseBase` to be used with any data type, making it highly flexible and suitable for a wide range of applications.\n\n## Example Usage\n\n### Returning a Response from a Service\n\nHere’s a simple example of using `ResponseBase` in a service method:\n\n```csharp\npublic ResponseBase\u003cUser\u003e GetUserById(int userId)\n{\n    var result = new ResponseBase\u003cUser\u003e();\n    var user = _userRepository.FindById(userId);\n    if (user == null)\n    {\n        return result.NotFound(); // Sets status to NotFound and returns\n    }\n    return result.Success(user); // Sets status to Success and returns the user data\n}\n```\n\nReturning a Response from an API Controller :\n\nIn an ASP.NET Core API controller, you can return a ResponseBase directly due to its implicit conversion to ObjectResult:\n```csharp\n[HttpGet(\"{id}\")]\npublic IActionResult GetUser(int id)\n{\n      var response = _userService.GetUserById(id);\n      return response; // Implicitly converts to ObjectResult\n}\n```\n\nYou can also convert HTTP status codes directly into ResponseBase:\n\n```csharp\npublic ResponseBase\u003cstring\u003e DeleteUser(int userId)\n{\n    var result = _userRepository.Delete(userId);\n    if (!result)\n    {\n        return HttpStatusCode.BadRequest; // Converts to ResponseBase with appropriate status\n    }\n\n    return HttpStatusCode.OK; // Converts to ResponseBase with status success\n}\n```\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikoo-asadnejad%2Fresponsebase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikoo-asadnejad%2Fresponsebase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikoo-asadnejad%2Fresponsebase/lists"}