{"id":16953494,"url":"https://github.com/nunogois/net5-webapi","last_synced_at":"2025-04-11T21:22:11.805Z","repository":{"id":54552438,"uuid":"337907662","full_name":"nunogois/net5-webapi","owner":"nunogois","description":".NET 5.0 Docker-ready C# REST API example using JWT authentication, Swagger, Newtonsoft JSON, and Dapper with SQL Server.","archived":false,"fork":false,"pushed_at":"2021-02-11T14:08:00.000Z","size":87,"stargazers_count":13,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T17:21:16.717Z","etag":null,"topics":["cross-platform","csharp","dapper","docker","jwt-authentication","net5","netcore-webapi","newtonsoft-json","rest-api","sql-server","swagger"],"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/nunogois.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":"2021-02-11T02:08:53.000Z","updated_at":"2023-04-08T18:30:06.000Z","dependencies_parsed_at":"2022-08-13T19:30:36.092Z","dependency_job_id":null,"html_url":"https://github.com/nunogois/net5-webapi","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nunogois%2Fnet5-webapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nunogois%2Fnet5-webapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nunogois%2Fnet5-webapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nunogois%2Fnet5-webapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nunogois","download_url":"https://codeload.github.com/nunogois/net5-webapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248480622,"owners_count":21110981,"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":["cross-platform","csharp","dapper","docker","jwt-authentication","net5","netcore-webapi","newtonsoft-json","rest-api","sql-server","swagger"],"created_at":"2024-10-13T22:07:16.336Z","updated_at":"2025-04-11T21:22:11.784Z","avatar_url":"https://github.com/nunogois.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n# net5-webapi\n\n.NET 5.0 Docker-ready C# REST API example using JWT authentication, Swagger, Newtonsoft JSON, and Dapper with SQL Server.\n\n![net5-webapi](https://github.com/nunogois/net5-webapi/blob/master/net5-webapi-thumbnail.png)\n\n![.NET 5.0](https://img.shields.io/badge/-.NET_5.0-141321?style=for-the-badge\u0026logo=.net\u0026logoColor=ba46d8)\u0026nbsp;\n![C#](https://img.shields.io/badge/-C%23-141321?style=for-the-badge\u0026logo=c-sharp\u0026logoColor=239120)\u0026nbsp;\n![Docker-ready](https://img.shields.io/badge/-Docker--ready-141321?style=for-the-badge\u0026logo=Docker\u0026logoColor=2496ED)\u0026nbsp;\n![Swagger](https://img.shields.io/badge/-Swagger-141321?style=for-the-badge\u0026logo=Swagger\u0026logoColor=85EA2D)\u0026nbsp;\n![JWT Authentication](https://img.shields.io/badge/-JWT_Authentication-141321?style=for-the-badge\u0026logo=JSON-Web-Tokens\u0026logoColor=ffffff)\u0026nbsp;\n![Dapper -\u003e SQL Server](https://img.shields.io/badge/-Dapper_--\u003e_SQL%20Server-141321?style=for-the-badge\u0026logo=Microsoft-SQL-Server\u0026logoColor=CC2927)\u0026nbsp;\n\n## Swagger\n\nWhen you first run this project on dev, you should be greeted by [Swagger](https://swagger.io/), listing all the available endpoints automatically and allowing you to try them.\n\nThis assumes the methods are working properly, so you'll need to setup your own JWT configuration, database connection and queries first. Check below for more information.\n\n### Swagger - Authorization\n\nAfter logging in with `POST /api/Auth/Login` you will receive a token ([JWT](https://jwt.io/)) along with session info. \n\nYou can use that token to authenticate in Swagger. Simply click on **Authorize** on the top right corner and enter `Bearer *your_token*` in the dialog. If the token is valid, you should be able to request authenticated routes like the ones in **Notes**.\n\n## DBConnection (Dapper -\u003e SQL Server)\n\nI'm using **DBEngine** as an example interface for your preferred database. Feel free to use Entity Framework if you prefer, for example. I like using [Dapper](https://github.com/StackExchange/Dapper) because I find it extremely fast and flexible.\n\nThe connection string is currently being fetched from **ConnectionStrings.DBConnection** in **appsettings.json**.\n\nThe [SQL Server](https://www.microsoft.com/sql-server/sql-server-2019?rtc=1) queries I'm using are just examples, adapt to your own database schema and needs.\n\n## JWT Authentication\n\nJWT configuration is currently being fetched from **JWT** in **appsettings.json**.\n\n - **Issuer** - Add your JWT issuer;\n - **Key** - Add your JWT key;\n - **ExpireMinutes** - Add your JWT expiration minutes - evaluate accordingly, it might make sense to automatically refresh the JWT in prod;\n\n## Docker\n\nSince this is a [.NET 5.0](https://docs.microsoft.com/en-us/dotnet/core/dotnet-five) project, it is cross-platform and this means it can also be easily containerized in Docker. Obviously, this doesn't mean you need to run this project in Docker, however the option is available. If you're using Visual Studio, you can easily switch between debug profiles on the debug dropdown.\n\nI suggest exploring **Dockerfile** and **launchSettings.json** for more information.\n\n## Controllers\n\n### Auth\n\n - **POST /api/Auth/Login** - Login with username and password. No previous authorization required.\n - **POST /api/Auth/Register** - Register with username, email, name and password. No previous authorization required.\n - **GET /api/Auth/Session** - Returns the session data for this user.\n \n### Notes\n\n - **GET /api/Notes** - Returns all the Notes for this user.\n - **POST /api/Notes** - Creates a new Note for this user.\n - **GET /api/Notes/{id}** - Returns a specific Note (id) for this user.\n - **PUT /api/Notes/{id}** - Updates a specific Note (id) for this user.\n - **DELETE /api/Notes/{id}** - Deletes a specific Note (id) for this user.\n \n## Engines\n\n### DBEngine\n\nUse DBEngine as a template to your own database interface. In my case: Dapper and SQL Server. \n\nCheck IDBEngine for more information on the methods.\n\n### CryptoEngine\n\nUse CryptoEngine to execute cryptography methods. This is basically a wrapper for [CryptoHelper](https://github.com/henkmollema/CryptoHelper). \n\nCheck ICryptoEngine for more information on the methods.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnunogois%2Fnet5-webapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnunogois%2Fnet5-webapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnunogois%2Fnet5-webapi/lists"}