{"id":23602648,"url":"https://github.com/carlosbrunetti/respify","last_synced_at":"2026-02-10T15:43:14.446Z","repository":{"id":269344604,"uuid":"906685920","full_name":"carlosbrunetti/Respify","owner":"carlosbrunetti","description":"Respify is a .NET library designed to simplify the creation of standardized API responses. It provides a set of helper methods and response classes to ensure consistent and clear communication between your API and its consumers. Key features include support for paginated and non-paginated responses, as well as custom responses.","archived":false,"fork":false,"pushed_at":"2025-01-14T13:37:08.000Z","size":431,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-01-14T14:43:12.732Z","etag":null,"topics":["api","api-response","csharp","custom-responses","dotnet","dotnet-core","non-paginated-responses","open-source","paginated-responses","standardized-responses"],"latest_commit_sha":null,"homepage":"","language":"C#","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/carlosbrunetti.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}},"created_at":"2024-12-21T15:56:19.000Z","updated_at":"2025-01-14T13:28:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"86dfec59-ff07-43ae-8dd7-02aecf728e1a","html_url":"https://github.com/carlosbrunetti/Respify","commit_stats":null,"previous_names":["carlosbrunetti/respify"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carlosbrunetti%2FRespify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carlosbrunetti%2FRespify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carlosbrunetti%2FRespify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/carlosbrunetti%2FRespify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/carlosbrunetti","download_url":"https://codeload.github.com/carlosbrunetti/Respify/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239449583,"owners_count":19640535,"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":["api","api-response","csharp","custom-responses","dotnet","dotnet-core","non-paginated-responses","open-source","paginated-responses","standardized-responses"],"created_at":"2024-12-27T12:12:11.386Z","updated_at":"2025-11-05T06:30:36.098Z","avatar_url":"https://github.com/carlosbrunetti.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"images/respify.jpeg\" alt=\"Project Logo\" width=\"400\" height=\"400\"\u003e\n\u003c/p\u003e\n\n# Respify\n\nRespify is a C# library designed to standardize API responses. It provides a consistent structure for both paginated and non-paginated data, making it easier to handle API responses in a uniform way.\n\n[![NuGet](https://img.shields.io/nuget/v/Respify.svg)](https://www.nuget.org/packages/Respify/)\n[![NuGet](https://img.shields.io/nuget/dt/Respify.svg)](https://www.nuget.org/packages/Respify/)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=carlosbrunetti_Respify\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=carlosbrunetti_Respify)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=carlosbrunetti_Respify\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=carlosbrunetti_Respify)\n[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=carlosbrunetti_Respify\u0026metric=bugs)](https://sonarcloud.io/dashboard?id=carlosbrunetti_Respify)\n[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=carlosbrunetti_Respify\u0026metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=carlosbrunetti_Respify)\n[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=carlosbrunetti_Respify\u0026metric=code_smells)](https://sonarcloud.io/dashboard?id=carlosbrunetti_Respify)\n\n## Installation\n\nTo install Respify, you can add it to your project via NuGet Package Manager:\n\n```sh\ndotnet add package Respify\n```\n\n## Generating Success Responses\n\nYou can generate success responses for both paginated and non-paginated return object using the `ResponseHelper` class.\n\n### Paginated Response\n\n```csharp\nusing Respify;\nusing Respify.helpers;\n\nvar cars = new List\u003cCar\u003e();\nvar paginatedResponse = new PaginatedResponse\u003cList\u003cCar\u003e\u003e(Items: cars, Count: cars.Count, PageNumber: 1, PageSize: 15, OrderBy: \"Make\", SortBy: \"desc\");\nvar response = ResponseHelper.Success(Data: paginatedResponse, Message: \"Success\", StatusCode: 200);\n```\n\n### Non-Paginated Response\n\n```csharp\nusing Respify;\nusing Respify.helpers;\n\nvar cars = new List\u003cCar\u003e();\nvar nonPaginatedResponse = new NonPaginatedResponse\u003cList\u003cCar\u003e\u003e(Items: cars, Count: cars.Count);\nvar response = ResponseHelper.Success(Data: nonPaginatedResponse, Message: \"Success\", StatusCode: 200);\n```\n\n## Generating Failure Responses\n\nYou can generate failure responses with optional return object and a list of errors.\n\n```csharp\nusing Respify;\nusing Respify.helpers;\n\nvar response = ResponseHelper.Failure\u003cobject\u003e(Data: null, Message: \"Failure\", StatusCode: 400);\n```\n\nOr\n\nYou also can generate failure responses with optional 'Message' with a list of errors.\n\n```csharp\nusing Respify;\nusing Respify.helpers;\n\nvar errors = new List\u003cstring\u003e();\nvar response = ResponseHelper.Failure\u003cobject\u003e(Data: null, Message: null, StatusCode: 400, Errors: errors);\n```\n\n## Creating Custom Responses\n\nYou can create custom responses with specific object, message, status code, success flag, and errors.\n\n```csharp\nusing Respify;\nusing Respify.helpers;\n\nint id = 1;\nvar response = ResponseHelper.CreateResponse(Data: id, Message: \"message\", StatusCode: 201, Success: true, Errors: null);\n```\nOr\n```csharp\nvar response = ResponseHelper.CreateResponse\u003cobject\u003e(Data: null, Message: \"message\", StatusCode: 201, Success: true, Errors: null);\n```\n## Converting Response to ObjectResult\nUsing ToResult() and ToResultAsync() methods, you can convert the response to an ObjectResult.\n\n```csharp\nvar response = new RespifyResponse\u003cstring\u003e(\"data\", \"Operation successful\", true, 200);\nvar result = response.ToResult();\n```\n### Asynchronous Response Conversion\n```csharp\nvar response = new RespifyResponse\u003cstring\u003e(\"data\", \"Operation successful\", true, 200);\nvar result = await response.ToResultAsync();\n```\n\n## Json Output\n\n### Paginated Response\n\n```json\n{\n    \"data\": {\n        \"items\": [],\n        \"count\": 0,\n        \"pageNumber\": 1,\n        \"pageSize\": 15,\n        \"orderBy\": \"Make\",\n        \"sortBy\": \"desc\"\n    },\n    \"message\": \"Success\",\n    \"success\": true,\n    \"errors\": null\n}\n\n```\n\n### Non-Paginated Response\n\n```json\n{\n    \"data\": {\n        \"items\": [],\n        \"count\": 0\n    },\n    \"message\": \"Success\",\n    \"success\": true,\n    \"errors\": null\n}\n```\n\n### Custom Response\n\n```json\n{\n  \"data\": 1,\n  \"message\": \"Created\",\n  \"success\": true,\n  \"errors\": null\n}\n```\n### Failure Response\n\n```json\n{\n  \"data\": null,\n  \"message\": \"\",\n  \"success\": false,\n  \"errors\": [\"Error 1\", \"Error 2\"]\n}\n```\n\n## Classes\n\n### NonPaginatedData\n\nRepresents non-paginated data.\n\n```csharp\n/// \u003csummary\u003e\n/// Represents a non-paginated response.\n/// \u003c/summary\u003e\n/// \u003ctypeparam name=\"T\"\u003eThe type of the items in the response.\u003c/typeparam\u003e\npublic class NonPaginatedResponse\u003cT\u003e : INonPaginatedResponse\u003cT\u003e\n{\n    /// \u003csummary\u003e\n    /// Initializes a new instance of the \u003csee cref=\"NonPaginatedResponse{T}\"/\u003e class.\n    /// \u003c/summary\u003e\n    /// \u003cparam name=\"items\"\u003eThe items in the response.\u003c/param\u003e\n    /// \u003cparam name=\"total\"\u003eThe total count of items in the response.\u003c/param\u003e\n    public NonPaginatedResponse(T items, int total) =\u003e (Items, Count) = (items, total);\n    \n    /// \u003csummary\u003e\n    /// Gets or sets the items in the response.\n    /// \u003c/summary\u003e\n    public T Items { get; set; }\n\n    /// \u003csummary\u003e\n    /// Gets or sets the count of items in the response.\n    /// \u003c/summary\u003e\n    public int Count { get; set; }\n}\n```\n\n### PaginatedData\n\nRepresents paginated data.\n\n```csharp\n/// \u003csummary\u003e\n/// Represents a paginated response.\n/// \u003c/summary\u003e\n/// \u003ctypeparam name=\"T\"\u003eThe type of the items in the response.\u003c/typeparam\u003e\npublic class PaginatedResponse\u003cT\u003e : IPaginatedResponse\u003cT\u003e\n{\n    /// \u003csummary\u003e\n    /// Initializes a new instance of the \u003csee cref=\"PaginatedResponse{T}\"/\u003e class.\n    /// \u003c/summary\u003e\n    /// \u003cparam name=\"items\"\u003eThe items in the response.\u003c/param\u003e\n    /// \u003cparam name=\"total\"\u003eThe total count of items in the response.\u003c/param\u003e\n    /// \u003cparam name=\"page\"\u003eThe current page number.\u003c/param\u003e\n    /// \u003cparam name=\"pageSize\"\u003eThe size of the page.\u003c/param\u003e\n    /// \u003cparam name=\"orderBy\"\u003eThe field by which the items are ordered.\u003c/param\u003e\n    /// \u003cparam name=\"sort\"\u003eThe field by which the items are sorted.\u003c/param\u003e\n    public PaginatedResponse(T items, int total, int page, int pageSize, string orderBy, string sort)\n    {\n        Items = items;\n        Count = total;\n        PageNumber = page;\n        PageSize = pageSize;\n        OrderBy = orderBy;\n        SortBy = sort;\n    }\n\n    /// \u003csummary\u003e\n    /// Gets or sets the items in the response.\n    /// \u003c/summary\u003e\n    public T Items { get; set; }\n\n    /// \u003csummary\u003e\n    /// Gets or sets the count of items in the response.\n    /// \u003c/summary\u003e\n    public int Count { get; set; }\n\n    /// \u003csummary\u003e\n    /// Gets or sets the current page number.\n    /// \u003c/summary\u003e\n    public int PageNumber { get; set; }\n\n    /// \u003csummary\u003e\n    /// Gets or sets the size of the page.\n    /// \u003c/summary\u003e\n    public int PageSize { get; set; }\n\n    /// \u003csummary\u003e\n    /// Gets or sets the field by which the items are ordered.\n    /// \u003c/summary\u003e\n    public string OrderBy { get; set; }\n\n    /// \u003csummary\u003e\n    /// Gets or sets the field by which the items are sorted.\n    /// \u003c/summary\u003e\n    public string SortBy { get; set; }\n}\n```\n### RespifyResponse\u003cT\u003e\n\nRepresents a standardized API response.\n\n```csharp\n/// \u003csummary\u003e\n/// Represents a standardized response object used in the Respify framework.\n/// \u003c/summary\u003e\n/// \u003ctypeparam name=\"T\"\u003eThe type of the data being returned in the response.\u003c/typeparam\u003e\npublic class RespifyResponse\u003cT\u003e : IRespifyResponse\u003cT\u003e\n{\n    /// \u003csummary\u003e\n    /// Initializes a new instance of the \u003csee cref=\"RespifyResponse{T}\"/\u003e class.\n    /// \u003c/summary\u003e\n    /// \u003cparam name=\"data\"\u003eThe data being returned in the response.\u003c/param\u003e\n    /// \u003cparam name=\"message\"\u003eThe message associated with the response.\u003c/param\u003e\n    /// \u003cparam name=\"success\"\u003eA value indicating whether the response indicates a successful operation.\u003c/param\u003e\n    /// \u003cparam name=\"statusCode\"\u003eThe HTTP status code associated with the response.\u003c/param\u003e\n    /// \u003cparam name=\"errors\"\u003eA list of errors associated with the response.\u003c/param\u003e\n    public RespifyResponse(T? data, string? message, bool success, int statusCode, List\u003cstring\u003e? errors)\n    {\n        Data = data;\n        Message = message;\n        Success = success;\n        StatusCode = statusCode;\n        Errors = errors;\n    }\n\n    /// \u003csummary\u003e\n    /// Initializes a new instance of the \u003csee cref=\"RespifyResponse{T}\"/\u003e class.\n    /// \u003c/summary\u003e\n    /// \u003cparam name=\"data\"\u003eThe data being returned in the response.\u003c/param\u003e\n    /// \u003cparam name=\"message\"\u003eThe message associated with the response.\u003c/param\u003e\n    /// \u003cparam name=\"success\"\u003eA value indicating whether the response indicates a successful operation.\u003c/param\u003e\n    /// \u003cparam name=\"statusCode\"\u003eThe HTTP status code associated with the response.\u003c/param\u003e\n    public RespifyResponse(T? data, string message, bool success, int statusCode)\n    {\n        Data = data;\n        Message = message;\n        Success = success;\n        StatusCode = statusCode;\n    }\n\n    /// \u003csummary\u003e\n    /// Gets or sets the data being returned in the response.\n    /// \u003c/summary\u003e\n    public T? Data { get; set; }\n\n    /// \u003csummary\u003e\n    /// Gets or sets the message associated with the response.\n    /// \u003c/summary\u003e\n    public string? Message { get; set; }\n\n    /// \u003csummary\u003e\n    /// Gets or sets a value indicating whether the response indicates a successful operation.\n    /// \u003c/summary\u003e\n    public bool Success { get; set; }\n\n    /// \u003csummary\u003e\n    /// Gets or sets the HTTP status code associated with the response.\n    /// \u003c/summary\u003e\n    [JsonIgnore]\n    public int StatusCode { get; set; }\n\n    /// \u003csummary\u003e\n    /// Gets or sets a list of errors associated with the response.\n    /// \u003c/summary\u003e\n    public List\u003cstring\u003e? Errors { get; set; }\n\n    /// \u003csummary\u003e\n    /// Converts the response to an \u003csee cref=\"ObjectResult\"/\u003e.\n    /// \u003c/summary\u003e\n    /// \u003creturns\u003eAn \u003csee cref=\"ObjectResult\"/\u003e representing the response.\u003c/returns\u003e\n    public ObjectResult ToResult()\n    {\n        return new ObjectResult(this)\n        {\n            StatusCode = this.StatusCode\n        };\n    }\n\n    /// \u003csummary\u003e\n    /// Asynchronously converts the response to an \u003csee cref=\"ObjectResult\"/\u003e.\n    /// \u003c/summary\u003e\n    /// \u003creturns\u003eA \u003csee cref=\"Task{TResult}\"/\u003e representing the asynchronous operation, with an \u003csee cref=\"ObjectResult\"/\u003e as the result.\u003c/returns\u003e\n    public async Task\u003cObjectResult\u003e ToResultAsync()\n    {\n        return await Task.FromResult(new ObjectResult(this)\n        {\n            StatusCode = this.StatusCode\n        });\n    }\n}\n```\n### ResponseHelper\nProvides helper methods to generate standardized API responses.\n\n```csharp\nusing Respify.Interfaces;\n\nnamespace Respify.helpers;\n\n/// \u003csummary\u003e\n/// Provides helper methods to generate standardized API responses.\n/// \u003c/summary\u003e\npublic static class ResponseHelper\n{\n    /// \u003csummary\u003e\n    /// Generates a success response for paginated data.\n    /// \u003c/summary\u003e\n    /// \u003ctypeparam name=\"T\"\u003eThe type of the data items.\u003c/typeparam\u003e\n    /// \u003cparam name=\"data\"\u003eThe paginated response data.\u003c/param\u003e\n    /// \u003cparam name=\"message\"\u003eThe success message.\u003c/param\u003e\n    /// \u003cparam name=\"statusCode\"\u003eThe HTTP status code (default is 200).\u003c/param\u003e\n    /// \u003creturns\u003eA standardized success response.\u003c/returns\u003e\n    public static RespifyResponse\u003cIPaginatedResponse\u003cT\u003e\u003e Success\u003cT\u003e(PaginatedResponse\u003cT\u003e data, string message, int statusCode = 200)\n    {\n        return new RespifyResponse\u003cIPaginatedResponse\u003cT\u003e\u003e(data, message, true, statusCode, null);\n    }\n\n    /// \u003csummary\u003e\n    /// Generates a success response for non-paginated data.\n    /// \u003c/summary\u003e\n    /// \u003ctypeparam name=\"T\"\u003eThe type of the data items.\u003c/typeparam\u003e\n    /// \u003cparam name=\"data\"\u003eThe non-paginated response data.\u003c/param\u003e\n    /// \u003cparam name=\"message\"\u003eThe success message.\u003c/param\u003e\n    /// \u003cparam name=\"statusCode\"\u003eThe HTTP status code (default is 200).\u003c/param\u003e\n    /// \u003creturns\u003eA standardized success response.\u003c/returns\u003e\n    public static RespifyResponse\u003cINonPaginatedResponse\u003cT\u003e\u003e Success\u003cT\u003e(NonPaginatedResponse\u003cT\u003e data, string message, int statusCode = 200)\n    {\n        return new RespifyResponse\u003cINonPaginatedResponse\u003cT\u003e\u003e(data, message, true, statusCode, null);\n    }\n\n    /// \u003csummary\u003e\n    /// Creates a custom response.\n    /// \u003c/summary\u003e\n    /// \u003ctypeparam name=\"T\"\u003eThe type of the data.\u003c/typeparam\u003e\n    /// \u003cparam name=\"data\"\u003eThe response data.\u003c/param\u003e\n    /// \u003cparam name=\"message\"\u003eThe response message.\u003c/param\u003e\n    /// \u003cparam name=\"statusCode\"\u003eThe HTTP status code.\u003c/param\u003e\n    /// \u003cparam name=\"success\"\u003eIndicates if the response is successful.\u003c/param\u003e\n    /// \u003cparam name=\"errors\"\u003eA list of errors (if any).\u003c/param\u003e\n    /// \u003creturns\u003eA standardized response.\u003c/returns\u003e\n    public static RespifyResponse\u003cT\u003e CreateResponse\u003cT\u003e(T? data, string? message, int statusCode, bool success, List\u003cstring\u003e? errors)\n    {\n        return new RespifyResponse\u003cT\u003e(data, message, success, statusCode, errors);\n    }\n\n    /// \u003csummary\u003e\n    /// Generates a failure response with optional data.\n    /// \u003c/summary\u003e\n    /// \u003ctypeparam name=\"T\"\u003eThe type of the data.\u003c/typeparam\u003e\n    /// \u003cparam name=\"data\"\u003eThe response data (optional).\u003c/param\u003e\n    /// \u003cparam name=\"message\"\u003eThe failure message.\u003c/param\u003e\n    /// \u003cparam name=\"statusCode\"\u003eThe HTTP status code (default is 400).\u003c/param\u003e\n    /// \u003creturns\u003eA standardized failure response.\u003c/returns\u003e\n    public static RespifyResponse\u003cT\u003e Failure\u003cT\u003e(T? data, string message, int statusCode = 400)\n    {\n        return new RespifyResponse\u003cT\u003e(data, message, false, statusCode);\n    }\n\n    /// \u003csummary\u003e\n    /// Generates a failure response with optional data and a list of errors.\n    /// \u003c/summary\u003e\n    /// \u003ctypeparam name=\"T\"\u003eThe type of the data.\u003c/typeparam\u003e\n    /// \u003cparam name=\"data\"\u003eThe response data (optional).\u003c/param\u003e\n    /// \u003cparam name=\"message\"\u003eThe failure message.\u003c/param\u003e\n    /// \u003cparam name=\"errors\"\u003eA list of errors.\u003c/param\u003e\n    /// \u003cparam name=\"statusCode\"\u003eThe HTTP status code (default is 400).\u003c/param\u003e\n    /// \u003creturns\u003eA standardized failure response.\u003c/returns\u003e\n    public static RespifyResponse\u003cT\u003e Failure\u003cT\u003e(T? data, string message, List\u003cstring\u003e errors, int statusCode = 400)\n    {\n        return new RespifyResponse\u003cT\u003e(data, message, false, statusCode, errors);\n    }\n}\n```\n\n## License\n\nThis project is licensed under the MIT License.\n\nThis `README.md` file provides an overview of the Respify library, installation instructions, usage examples, and class definitions.\nRespify is a C# library designed to standardize API responses. It provides a consistent structure for both paginated and non-paginated data, making it easier to handle API responses in a uniform way.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarlosbrunetti%2Frespify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcarlosbrunetti%2Frespify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarlosbrunetti%2Frespify/lists"}