{"id":31790137,"url":"https://github.com/cmiles74/webapi","last_synced_at":"2025-10-10T15:25:24.385Z","repository":{"id":42848140,"uuid":"474373969","full_name":"cmiles74/WebAPI","owner":"cmiles74","description":"Leverages Nervestaple libraries to make WebAPI a breeze! 🌊","archived":false,"fork":false,"pushed_at":"2022-03-26T16:19:04.000Z","size":69,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-10T07:49:13.629Z","etag":null,"topics":["c-sharp","library","restful","webapi"],"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/cmiles74.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}},"created_at":"2022-03-26T14:37:07.000Z","updated_at":"2022-03-26T16:24:53.000Z","dependencies_parsed_at":"2022-08-23T14:10:13.701Z","dependency_job_id":null,"html_url":"https://github.com/cmiles74/WebAPI","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cmiles74/WebAPI","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmiles74%2FWebAPI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmiles74%2FWebAPI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmiles74%2FWebAPI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmiles74%2FWebAPI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cmiles74","download_url":"https://codeload.github.com/cmiles74/WebAPI/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmiles74%2FWebAPI/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279004579,"owners_count":26083735,"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-10T02:00:06.843Z","response_time":62,"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":["c-sharp","library","restful","webapi"],"created_at":"2025-10-10T15:25:23.355Z","updated_at":"2025-10-10T15:25:24.378Z","avatar_url":"https://github.com/cmiles74.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Continuous Integration](https://github.com/cmiles74/WebApi/actions/workflows/ci.yml/badge.svg)\r\n\r\n# Nervestaple.WebAPI\r\n\r\nThis library leverages the [Nervestaple.WebService][0] project and \r\n[Microsoft's WebAPI library][2] to make it way easy to build out RESTful web \r\nservices. It's available on [NuGet.org][3], you may follow the direction on\r\nthat page to add it to your project.\r\n\r\n* [Nervestaple.WebApi NuGet Package][3]\r\n\r\n```cs\r\n[ApiVersion(\"1.0\")]\r\n[Route(\"api/v{version:apiVersion}/[controller]\")]\r\npublic class ToDoItemController : ToDoReadWriteController\u003cToDoItem, long\u003e, IToDoItemController\r\n{\r\n    public ToDoItemController(IToDoItemService service) : base(service) {\r\n\r\n    }\r\n    \r\n    [HttpGet]\r\n    [SwaggerResponse(200, \"Returning an page of item resources\", \r\n        typeof(HalResource\u003cIEnumerable\u003cHalResource\u003cToDoItem\u003e\u003e\u003e))]\r\n    public IActionResult Get([FromQuery] SimplePageParameters parameters) {\r\n        return base.handleGet(parameters);\r\n    }\r\n\r\n    [HttpGet(\"{id}\")]\r\n    [SwaggerResponse(200, \"Returning the item with the matching unique identifier\",\r\n        typeof(HalResource\u003cToDoItem\u003e))]\r\n    public IActionResult GetById(int id) {\r\n        return base.handleGetById(id);\r\n    }\r\n\r\n    [HttpPost(\"query\")]\r\n    [SwaggerResponse(200, \"Returning a set of matching item instances\",\r\n        typeof(HalResource\u003cIEnumerable\u003cHalResource\u003cToDoItem\u003e\u003e\u003e))]\r\n    public IActionResult Query([FromBody] ToDoItemParameters parameters) {\r\n        return handleQuery(parameters);\r\n    }\r\n    \r\n    [HttpPost]\r\n    public IActionResult Create([FromBody] ToDoItemEdit model) {\r\n        return base.handleCreate(model);\r\n    }\r\n    \r\n    [HttpPatch(\"{id}\")]\r\n    public IActionResult Update(long id, [FromBody] JsonPatchDocument\u003cAbstractEntity\u003e model) {\r\n        return base.handleUpdate(id, model);\r\n    }\r\n}\r\n```\r\n\r\nNote that while the example above has Swagger annotations, we haven't included\r\nSwagger in this package. If you would like to use it, all you need to do is add\r\nthe packages to your project. `;-)`\r\n\r\n```\r\n\u003cPackageReference Include=\"Swashbuckle.AspnetCore\" Version=\"6.0.7\" /\u003e\r\n\u003cPackageReference Include=\"Swashbuckle.AspnetCore.Annotations\" Version=\"6.0.7\" /\u003e\r\n\u003cPackageReference Include=\"Swashbuckle.AspnetCore.Swagger\" Version=\"6.0.7\" /\u003e\r\n\u003cPackageReference Include=\"Nervestaple.WebApi\" Version=\"0.8.0\" /\u003e\r\n```\r\n\r\nThe controller above provides a RESTful API end point for adding and updating \r\nTo Do items, including the ability to update them with [JsonPatchDocument][1]\r\nobjects.\r\n\r\nYou may use our startup helper classes to make it easier to get Swagger and\r\nSwashbuckle configured for your application.\r\n\r\n```cs\r\npublic class Startup {\r\n\r\n  ...\r\n\r\n  // configure MVC...\r\n  MvcStartupHelper.ConfigureServices(\r\n    services, \r\n    new ApiVersion(1, 0));  // default API version\r\n  \r\n  // configure your swagger options...\r\n  services.AddTransient\u003cIConfigureOptions\u003cSwaggerGenOptions\u003e, ConfigureSwaggerOptions\u003e();\r\n  \r\n  // configure Swagger\r\n  SwaggerStartupHelper.ConfigureServices(\r\n    services, \r\n    Path.Combine(AppContext.BaseDirectory, \"YOUR_PROJECT_NAME.xml\"));\r\n}\r\n```\r\n\r\nIn the code above we configure the Swagger options with a custom class, \r\n`ConfigureSwaggerOptions`. Your options class should look something like the\r\nexample in `src\\Helpers\\SampleConfigureSwaggerOptions.cs`. \r\n\r\nAt this time both Swagger, Swashbuckle and the supporting tooling require that \r\nyou version your API, there's no getting around this requirement. If you really\r\ndon't want to version your API we suggest you use \"v0\" to indicate this.\r\n\r\nAlso note that you need to provide a path to your generated XML documentation\r\n(`msbuild` will put this together for you); Swashbuckle will scrape this file\r\n to provide better API documentation. If you aren't using XML comments... \r\n Well, you better start!\r\n \r\nThe last piece of the puzzle is to call out to the helper class in the \r\n`Configure` method of your `Startup.cs` file.\r\n\r\n```cs\r\npublic void Configure(\r\n            IConfiguration configuration,\r\n            IApplicationBuilder app, \r\n            IWebHostEnvironment env, \r\n            IApiVersionDescriptionProvider provider,\r\n            YourDbContext dbContext) {\r\n  ...\r\n\r\n  SwaggerStartupHelper.ConfigureApplication(app, provider, path);\r\n}\r\n```\r\n\r\nIn order to support authentication, we build on the services and models \r\nprovided by the Nervestaple.WebService project and provide an \r\n`AbstractAuthenticationController` that will pick up an `AccountService` from\r\nyour applications services and provided JWT bearer token authentication. It's \r\nas easy to use as...\r\n\r\n```cs\r\npublic class AuthenticationController : AbstractAuthenticationController\r\n{\r\n    public AuthenticationController(IAccountService service, SecurityConfiguration securityConfiguration)\r\n        : base(service, securityConfiguration)\r\n    {\r\n        \r\n    }\r\n}\r\n```\r\n\r\nThere's also a canned requirement and handler to ensure that authenticated \r\npeople are associated with a required set of roles, letting you setup your own\r\nauthorization policies...\r\n\r\n```cs\r\nservices.AddAuthorization(options =\u003e {\r\n    options.AddPolicy(\"Everyone\", policy =\u003e {\r\n        policy.Requirements.Add(new HasRoleRequirement(\"All Users\"));\r\n    });\r\n});\r\n```\r\n\r\nThat you can use to annotate your API methods, like so...\r\n\r\n```cs\r\n[Authorize(Policy = \"Everyone\")]\r\n[HttpPost]\r\npublic IActionResult Create([FromBody] ToDoContextEdit model) {\r\n    // you're code here!\r\n}\r\n```\r\n\r\nWe provide a helper that you may call at startup to setup JWT bearer \r\nauthentication for your application.\r\n\r\n```cs\r\nJwtStartupHelper.ConfigureJwtBearerAuthentication(Configuration, services);\r\n```\r\n\r\nAnd there's a small bit of glue code to ensure that Swashbuckle correctly \r\nhandles these annotations for Swagger.\r\n\r\n```cs\r\nservices.AddSwaggerGen(s =\u003e {\r\n     // your swashbuckle configuration...\r\n     JwtStartupHelper.ConfigureSwaggerGenForJwt(s);\r\n}); \r\n```\r\n\r\nThis library is a work in progress, please feel free to fork and send me pull\r\nrequests! `:-D`\r\n\r\n\r\n## Documentation\r\n\r\nThis project uses [Doxygen](http://www.doxygen.nl/) for documentation. Doxygen \r\nwill collect inline comments from your code, along with any accompanying README \r\nfiles, and create a documentation website for the project. If you do not have \r\nDoxygen installed, you can download it from their website and place it on your \r\npath. To run Doxygen...\r\n\r\n    $ cd src\r\n    $ doxygen\r\n\r\nThe documentation will be written to the `doc/html` folder at the root of the \r\nproject, you can read this documentation with your web browser.\r\n\r\n## Other Notes\r\n\r\nProject Icon made by [Freepik](https://www.freepik.com/) from \r\n[Flaticon](https://www.flaticon.com/) under the \r\n[Creative Commons license](http://creativecommons.org/licenses/by/3.0/).\r\n\r\n----\r\n\r\n[0]: https://github.com/cmiles74/WebService\r\n[1]: https://docs.microsoft.com/en-us/aspnet/core/web-api/jsonpatch\r\n[2]: https://docs.microsoft.com/en-us/aspnet/core/web-api/\r\n[3]: https://www.nuget.org/packages/Nervestaple.WebApi/","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmiles74%2Fwebapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcmiles74%2Fwebapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmiles74%2Fwebapi/lists"}