{"id":20138460,"url":"https://github.com/thiagobarradas/webapi-models","last_synced_at":"2025-04-09T18:08:48.264Z","repository":{"id":49305641,"uuid":"149396625","full_name":"ThiagoBarradas/webapi-models","owner":"ThiagoBarradas","description":"Models to facilitate implementation and handling successful and error responses in web api.","archived":false,"fork":false,"pushed_at":"2024-06-28T20:03:47.000Z","size":39,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-08T23:36:36.344Z","etag":null,"topics":["api","api-response","dotnet","dotnet-core","dotnet-standard","exception","generic","models","response","webapi"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/WebApi.Models/","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/ThiagoBarradas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","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":"2018-09-19T05:25:46.000Z","updated_at":"2025-02-02T22:02:03.000Z","dependencies_parsed_at":"2025-04-09T18:05:35.698Z","dependency_job_id":null,"html_url":"https://github.com/ThiagoBarradas/webapi-models","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/ThiagoBarradas%2Fwebapi-models","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThiagoBarradas%2Fwebapi-models/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThiagoBarradas%2Fwebapi-models/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThiagoBarradas%2Fwebapi-models/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ThiagoBarradas","download_url":"https://codeload.github.com/ThiagoBarradas/webapi-models/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085133,"owners_count":21045135,"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","dotnet","dotnet-core","dotnet-standard","exception","generic","models","response","webapi"],"created_at":"2024-11-13T21:38:15.433Z","updated_at":"2025-04-09T18:08:48.237Z","avatar_url":"https://github.com/ThiagoBarradas.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://barradas.visualstudio.com/Contributions/_apis/build/status/NugetPackage/WebApi%20Models?branchName=develop)](https://barradas.visualstudio.com/Contributions/_build/latest?definitionId=18\u0026branchName=develop)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ThiagoBarradas_webapi-models\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=ThiagoBarradas_webapi-models)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=ThiagoBarradas_webapi-models\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=ThiagoBarradas_webapi-models)\n[![NuGet Downloads](https://img.shields.io/nuget/dt/WebApi.Models.svg)](https://www.nuget.org/packages/WebApi.Models/)\n[![NuGet Version](https://img.shields.io/nuget/v/WebApi.Models.svg)](https://www.nuget.org/packages/WebApi.Models/)\n\n# WebApi.Models\n\nModels to facilitate implementation and handling successful and error responses in web api.\n\n# Sample\n\nSample - Entity to ApiResponse\n```c#\n\nvar apiResponse = myEntity.ToApiResponse(HttpStatusCode.OK);\n\n```\n\nSample with Exception\n```c#\n\n// Creating a exception with errors\n\nvar errors = new ErrorsReponse();\n\nresponse.AddError(\"message1\", \"property1\");\nresponse.AddError(\"message2\", \"property2\");\n\nthrow new BadRequestException(errors);\n\n// On your exception handler \n\nvar exceptionApiResponse = badRequestException.ToApiResponse();\n\n```\n\n\u003e You need implements `ApiResponse` mapping to your web api framework response, like ASP.NET or NancyFx model.\n\nSample - Casting ApiResponse to HttpResponseMessage\n```c#\n\npublic class BaseApiController : ApiController\n{\n    protected HttpResponseMessage CreateResponse(ApiResponse response)\n    {\n        var response = Request.CreateResponse(apiResponse.StatusCode, apiResponse.Content);\n        apiResponse.Headers.ForEach(header =\u003e \n        {\n            response.Headers.Add(header.Key, header.Value);\n        });\n\n        return response;\n    }\n}\n\npublic class MyController : BaseApiController\n{\n    [HttpGet]\n    [Route(\"\")]\n    public HttpResponseMessage GetSomething()\n    {\n        // do something and get ApiResponse\n\n        return this.CreateResponse(apiResponse);\n    }\n}\n```\n\n## Install via NuGet\n\n```\nPM\u003e Install-Package WebApi.Models\n```\n\n## How can I contribute?\nPlease, refer to [CONTRIBUTING](.github/CONTRIBUTING.md)\n\n## Found something strange or need a new feature?\nOpen a new Issue following our issue template [ISSUE_TEMPLATE](.github/ISSUE_TEMPLATE.md)\n\n## Changelog\nSee in [nuget version history](https://www.nuget.org/packages/WebApi.Models)\n\n## Did you like it? Please, make a donate :)\n\nif you liked this project, please make a contribution and help to keep this and other initiatives, send me some Satochis.\n\nBTC Wallet: `1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX`\n\n![1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX](https://i.imgur.com/mN7ueoE.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiagobarradas%2Fwebapi-models","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthiagobarradas%2Fwebapi-models","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthiagobarradas%2Fwebapi-models/lists"}