{"id":21252948,"url":"https://github.com/kevinhellos/dotnet-web-api","last_synced_at":"2025-08-31T15:18:11.256Z","repository":{"id":207732084,"uuid":"719956157","full_name":"kevinhellos/dotnet-web-api","owner":"kevinhellos","description":"Tutorial on building a web API using C# with Microsoft .NET","archived":false,"fork":false,"pushed_at":"2023-11-17T10:07:26.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T05:42:03.475Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/kevinhellos.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}},"created_at":"2023-11-17T09:08:21.000Z","updated_at":"2023-11-17T10:01:45.000Z","dependencies_parsed_at":"2023-11-17T10:42:37.705Z","dependency_job_id":null,"html_url":"https://github.com/kevinhellos/dotnet-web-api","commit_stats":null,"previous_names":["iskevinlemon/dotnet-web-api","kevinhellos/dotnet-web-api"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kevinhellos/dotnet-web-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhellos%2Fdotnet-web-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhellos%2Fdotnet-web-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhellos%2Fdotnet-web-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhellos%2Fdotnet-web-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinhellos","download_url":"https://codeload.github.com/kevinhellos/dotnet-web-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhellos%2Fdotnet-web-api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263503189,"owners_count":23476723,"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":[],"created_at":"2024-11-21T03:49:22.086Z","updated_at":"2025-07-04T11:38:59.396Z","avatar_url":"https://github.com/kevinhellos.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dotnet web api\nTutorial on building a web API using C# with Microsoft .NET\u003cbr/\u003e\n**For this tutorial, we will be using dotnet 6.**.\n\n# What you need to have\n- dotnet installed.  If you do not have installed, install it from \n\u003ca href=\"https://dotnet.microsoft.com/en-us/download/dotnet/6.0\" target=\"_blank\"\u003ehere (dotnet 6)\u003c/a\u003e. \u003cbr/\u003e\n- Visual Studio (purple icon) NOT vscode (blue icon). Install it from \n\u003ca href=\"https://visualstudio.microsoft.com/\" target=\"_blank\"\u003ehere\u003c/a\u003e. \u003cbr/\u003e\n\n# Quick Tutorial\n- Download the \u003ccode\u003eMenus API.sln\u003c/code\u003e from \u003ca target=\"blank\" href=\"https://github.com/iskevinlemon/dotnet-web-api/blob/main/Menus%20API.sln\"\u003ehere\u003c/a\u003e.\u003cbr/\u003e\n- Double click to run the solution.\u003cbr/\u003e\n\n# Manual Tutorial\n**Step 1 - Project Setup** \u003cbr/\u003e\n- launch Visual Studio and create a new project\u003cbr/\u003e\n- choose API as the template. On the dropdown menu, ensure it selects C#. Once done, click continue\n\u003cimg width=\"899\" alt=\"image\" src=\"https://github.com/iskevinlemon/dotnet-web-api/assets/126497052/c82698fd-4155-435f-956e-79db358c9f68\"\u003e\u003cbr/\u003e\n - On the Target Framework dropdown menu, ensure it selects .NET 6.0. On the Advanced, follow the settings as per image below. Once done, click continue\n\u003cimg width=\"900\" alt=\"image\" src=\"https://github.com/iskevinlemon/dotnet-web-api/assets/126497052/c9435a75-095c-462a-83d2-7cf581a18757\"\u003e\u003cbr/\u003e\n - For the purpose of this tutorial, my Project name will be Menus API as we will be working with menus. Feel free to choose your own directory for Location of the project. Once done, click Create\n\u003cimg width=\"900\" alt=\"image\" src=\"https://github.com/iskevinlemon/dotnet-web-api/assets/126497052/5eeb7ab0-be7e-4383-a533-8be3b9812d32\"\u003e\u003cbr/\u003e\n- When the project has been successfully created, your Visual Studio Solution Explorer should look something like this. Your Solution Explorer may look different, but it is alright\n\u003cimg width=\"1470\" alt=\"image\" src=\"https://github.com/iskevinlemon/dotnet-web-api/assets/126497052/90003292-f1d7-4a23-9b75-8dedeffaff37\"\u003e\u003cbr/\u003e\n\n**Step 2 - Deleting Boilerplate Codes** \u003cbr/\u003e\n- Inside the Solution Explorer, delete:\u003cbr/\u003e\n-- Controllers/\u003ccode\u003eWeatherForecastController.cs\u003c/code\u003e\u003cbr/\u003e\n-- \u003ccode\u003eWeatherForecast.cs\u003c/code\u003e\u003cbr/\u003e\n\n**Step 3 - Creating the MenusController** \u003cbr/\u003e\n- Inside the Controllers folder, create a new controller. Right click on Controllers folder,Add -\u003e New Class -\u003e ASP.NET Core -\u003e Controller Class. For the name, type MenusController.\u003cbr/\u003e\n- Inside the \u003ccode\u003eMenusController.cs\u003c/code\u003e, replace the whole source code with the codes below\u003cbr/\u003e\n```c#\n// MenusController.cs\n\nusing Microsoft.AspNetCore.Mvc;\nusing Microsoft.Extensions.Logging;\nusing System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace Menus_API.Controllers\n{\n    [ApiController]\n    [Route(\"/api/Menus\")] // defines the API route. In this case localhost:\u003cport_number\u003e/api/Menus\n\n    public class MenusController : ControllerBase\n    {\n        [HttpGet(Name = \"GetMenus\")]\n        public IEnumerable\u003cMenu\u003e Get()\n        {\n            // Sample data of menu items\n            // Creating a Menu List containg Menu Objects\n            var menus = new List\u003cMenu\u003e\n            {\n                new Menu { Id = 1, Name = \"Breakfast Menu\", Price = 10.99, Category = \"Breakfast\" },\n                new Menu { Id = 2, Name = \"Lunch Menu\", Price = 15.99, Category = \"Lunch\" },\n                new Menu { Id = 3, Name = \"Dinner Menu\", Price = 20.99, Category = \"Dinner\" }\n                // Add more menu objects as needed\n            };\n            return menus;\n        }\n\n    }\n\n    // Creating a Menu class\n    public class Menu\n    {\n        public int Id { get; set; }\n        public string Name { get; set; }\n        public double Price { get; set; }\n        public string Category { get; set; }\n    }\n\n}\n```\n**Step 4 - Configuring Project** \u003cbr/\u003e\n- Inside the Properties folder, open the \u003ccode\u003elaunchSettings.json\u003c/code\u003e\u003cbr/\u003e\n- Replace all contents of \u003ccode\u003elaunchSettings.json\u003c/code\u003e with the following codes\u003cbr/\u003e\n```json\n{\n  \"$schema\": \"https://json.schemastore.org/launchsettings.json\",\n  \"iisSettings\": {\n    \"windowsAuthentication\": false,\n    \"anonymousAuthentication\": true,\n    \"iisExpress\": {\n      \"applicationUrl\": \"http://localhost:33341\",\n      \"sslPort\": 44358\n    }\n  },\n  \"profiles\": {\n    \"Menus_API\": {\n      \"commandName\": \"Project\",\n      \"launchBrowser\": true,\n      \"launchUrl\": \"/api/Menus\",\n      \"applicationUrl\": \"https://localhost:7019;http://localhost:5009\",\n      \"environmentVariables\": {\n        \"ASPNETCORE_ENVIRONMENT\": \"Development\"\n      },\n      \"dotnetRunMessages\": true\n    },\n    \"IIS Express\": {\n      \"commandName\": \"IISExpress\",\n      \"launchBrowser\": true,\n      \"launchUrl\": \"/api/Menus\",\n      \"environmentVariables\": {\n        \"ASPNETCORE_ENVIRONMENT\": \"Development\"\n      }\n    }\n  }\n}\n```\n- Inside the Solution Explorer folder, open the \u003ccode\u003eProgram.cs\u003c/code\u003e\u003cbr/\u003e\n- Replace all contents of \u003ccode\u003eProgram.cs\u003c/code\u003e with the following codes\u003cbr/\u003e\n```c#\n// Program.cs\n\nvar builder = WebApplication.CreateBuilder(args);\n\n// Add services to the container.\n\nbuilder.Services.AddControllers();\n// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle\nbuilder.Services.AddEndpointsApiExplorer();\n// builder.Services.AddSwaggerGen();\n\nvar app = builder.Build();\n\n// Configure the HTTP request pipeline.\nif (app.Environment.IsDevelopment())\n{\n    // app.UseSwagger();\n    // app.UseSwaggerUI();\n}\n\napp.UseHttpsRedirection();\n\napp.UseAuthorization();\n\napp.MapControllers();\n\napp.Run();\n```\n- Click Run (play button) to build and launch the project\u003cbr/\u003e\n\u003cimg width=\"359\" alt=\"image\" src=\"https://github.com/iskevinlemon/dotnet-web-api/assets/126497052/23db52f0-5760-4c12-a8da-5a5c687cbd15\"\u003e\u003cbr/\u003e\n- If your project is setup and configured correctly, you should see the following on your browser. Url would be \u003ccode\u003elocalhost:YOUR_PORT/api/menus\u003c/code\u003e\u003cbr/\u003e\n![image](https://github.com/iskevinlemon/dotnet-web-api/assets/126497052/ca694714-d869-4a5c-8f89-1f9747d93563)\u003cbr/\u003e\n\n**End of tutorial** \u003cbr/\u003e\nSource code has also been provided in this repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinhellos%2Fdotnet-web-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinhellos%2Fdotnet-web-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinhellos%2Fdotnet-web-api/lists"}