{"id":27894,"date":"2022-06-17T12:30:14","date_gmt":"2022-06-17T12:30:14","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/blog\/?p=27894"},"modified":"2024-12-27T08:28:58","modified_gmt":"2024-12-27T08:28:58","slug":"web-api-in-net-6","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/blog\/web-api-in-net-6","title":{"rendered":"Web API in .NET 6.0 Tutorial: How to Build CRUD Operation"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>In this tutorial, we will build .NET 6 Web API that uses Entity Framework and SQL to create API endpoints. It will allow clients to perform CRUD operations in API on the data stored in the database.<\/p>\n<p>In our demo application, we will be using the database first approach. We will start with creating a table in the SQL database and then use an entity framework to create DBContext and Model.<\/p>\n<h2>What is Web API?<\/h2>\n<p>A Web API, or Application Programming Interface, is a platform designed to develop HTTP services that can be accessed by various client-side applications such as mobile devices, web browsers, and desktop applications. It acts as a medium for multiple applications to exchange data and interact with each other. <\/p>\n<p>Developers can create functions that can be requested through HTTP calls with API. This function allows you to save or retrieve data for your clients, enabling them to perform certain tasks and access specific information that is made available to them through the API.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/image-15.png\" alt=\"What is Web API?\" width=\"650\" height=\"354\" class=\"alignnone size-full wp-image-34657\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/image-15.png 650w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/image-15-300x163.png 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><br \/>\n<strong>Key features of API <\/strong><\/p>\n<ul class=\"bullets text-left\">\n<li>Supports HTTP verbs like GET, POST, PUT, DELETE, etc., which allows clients to perform different actions on the data <\/li>\n<li>Supports default responses such as XML and JSON, standard formats which help exchange data between the client and the server.<\/li>\n<li>API can define custom data which allows you to tailor the data as per client requirements<\/li>\n<li>APIs are either self-hosted or hosted by third parties, which means you have flexibility in using them.<\/li>\n<li>It allows easy authorization and authentication, which helps control access to API crud operations and protects your data.<\/li>\n<li>API is an ideal platform for building RESTful services for designing web services that are scalable, flexible, and easily maintained.<\/li>\n<\/ul>\n<h2>Why do we need Web API?<\/h2>\n<p>People nowadays use multiple devices such as smartphones, tablets, and iPhones; therefore, more than a web-based application is needed to reach out to all users. We need an API  to expose all these service data to all the different device apps and browsers. Adding a web API project makes it easier to bridge the two ends, making it easier to manage and update.<\/p>\n<p>In this case, we need a Web API to manage the database interactions and business logic between a website, an Android app, and an iOS app.<\/p>\n<p>All three applications can communicate with the database through the Web API project, which handles all database interactions and ensures that the database is not directly accessible through the websites or applications. <\/p>\n<p>By using a Web API, we can ensure secure and efficient communication between the different applications and devices, making it an essential tool in modern application development.<\/p>\n<h2>What&#8217;s new in .NET 6?<\/h2>\n<p>Let us have a look at some of the major highlights.<\/p>\n<ul class=\"bullets text-left\">\n<li><strong>Hot Reloading<\/strong> allows developers to modify the user interface while the application is still running. Changes are reflected in real-time without rebuilding or starting the app.<\/li>\n<li><strong>Minimal APIs<\/strong> for developers to build lightweight services without needing templates or controllers, using extension methods of \u201cEndpointConcentionBuilder\u201d in the Startup or Program class.<\/li>\n<li><strong>The HTTP logging middleware<\/strong> can log HTTP request and response information like headers, body, and properties to enhance debugging and monitoring<\/li>\n<li><strong>The Blazor<\/strong> web framework used for building interactive web applications with c# has improved performance, event binding, and support for pre-rendering components.<\/li>\n<li>ASP.NET Core program and Startup classes are merged to simplify the code structure.<\/li>\n<li><strong>Support for cloud-native development<\/strong> through integration with Kubernetes and other cloud platforms.<\/li>\n<li><strong>Enhanced JSON support<\/strong> through the introduction of a new source generator<\/li>\n<li>.NET Core has now improved <strong>support for gRPC and GraphQL APIs.<\/strong><br \/>\nThe use of OpenSSL 3 and support for runtime defense-in-depth mitigations enhance the security of the .NET core.<\/li>\n<li><strong>Support for Single-file applications without extraction<\/strong> on Windows, macOS, and Linux.<\/li>\n<li>The re-written FileStream improves performance for I\/O operations, especially for file I\/O.<\/li>\n<li><strong>Improved source code generation<\/strong> with a new source generator framework.<\/li>\n<li><strong>Improved .NET MAUI (Multi-platform App UI)<\/strong> support for building cross-platform mobile and desktop apps.<\/li>\n<li><strong>Improvements to the .NET runtime<\/strong> include enhanced garbage collection, improved ARM-based platforms performance, and hardware intrinsics support.<\/li>\n<li><strong>Entity Framework Core<\/strong> has improved support for Cosmos DB and a new LINQ syntax for querying nested JSON data.<\/li>\n<li><strong>Visual Studio tooling<\/strong> has improved with new project templates and integration with GitHub.<\/li>\n<\/ul>\n<h2>Prerequisites: Web API in .NET 6.0<\/h2>\n<ul class=\"bullets text-left\">\n<li>Visual Studio 2022.<\/li>\n<li>.NET SDK 6.0.<\/li>\n<li>Sql-Server.<\/li>\n<ul>\n<h2>Create Project<\/h2>\n<p>Start Visual Studio and create a new project with the type <strong>ASP.NET Core Web API<\/strong> and click Next.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1100\" height=\"725\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/1-min.png\" alt=\"Create a new project with .net\" class=\"alignnone size-medium wp-image-27925\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/1-min.png 1100w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/1-min-300x198.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/1-min-1024x675.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/1-min-768x506.png 768w\" sizes=\"auto, (max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<p>Enter the project name <strong>ProductCrudAPI,<\/strong> select the location where you want to save your project, and click <strong>Next.<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1100\" height=\"721\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/2-min.png\" alt=\"configure new project with .net\" class=\"alignnone size-medium wp-image-27910\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/2-min.png 1100w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/2-min-300x197.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/2-min-1024x671.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/2-min-768x503.png 768w\" sizes=\"auto, (max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<p>Select <strong>.Net 6.0<\/strong> (Long-term support) as a framework. Fill in the required information as shown in the below image, and click on <strong>Create.<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1100\" height=\"717\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/3-min.png\" alt=\"add additional information .net\" class=\"alignnone size-medium wp-image-27911\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/3-min.png 1100w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/3-min-300x196.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/3-min-1024x667.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/3-min-768x501.png 768w\" sizes=\"auto, (max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<p>Once you click on Create, a Web API project will be created.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1100\" height=\"519\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/4-min.png\" alt=\"Create Project with .net\" class=\"alignnone size-medium wp-image-27912\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/4-min.png 1100w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/4-min-300x142.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/4-min-1024x483.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/4-min-768x362.png 768w\" sizes=\"auto, (max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<h2>Add NuGet Packages<\/h2>\n<p>To use the <a href=\"https:\/\/www.bacancytechnology.com\/blog\/web-api-in-net-6\" target=\"_blank\" rel=\"noopener\">entity framework core<\/a> in our project, we need to <strong>install two NuGet packages:<\/strong><\/p>\n<ul class=\"bullets text-left\">\n<li>Microsoft.EntityFrameworkCore.Tools<\/li>\n<li>Microsoft.EntityFrameworkCore.SqlServer<\/li>\n<ul>\n<p>Follow the below instructions to install <strong>NuGet packages.<\/strong> <\/p>\n<p>Right-click on Dependencies and select <strong>Manage NuGet Packages.<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1100\" height=\"527\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/5-min.png\" alt=\"Add NuGet Packages with .net\" class=\"alignnone size-medium wp-image-27913\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/5-min.png 1100w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/5-min-300x144.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/5-min-1024x491.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/5-min-768x368.png 768w\" sizes=\"auto, (max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<p><strong>Microsoft.EntityFrameworkCore.Tools<\/strong><\/p>\n<p>Select the <strong>Browse<\/strong> tab and search for <strong>Microsoft.EntityFrameworkCore.Tools<\/strong> and install its latest stable version.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1100\" height=\"532\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/6-min.png\" alt=\"Add NuGet Packages with .net\" class=\"alignnone size-medium wp-image-27914\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/6-min.png 1100w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/6-min-300x145.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/6-min-1024x495.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/6-min-768x371.png 768w\" sizes=\"auto, (max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<p><strong>Microsoft.EntityFrameworkCore.SqlServer<\/strong><\/p>\n<p>Once the above package is installed, Search for <strong>Microsoft.EntityFrameworkCore.SqlServer<\/strong> and install its latest stable version.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1100\" height=\"527\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/7-min.png\" alt=\"Add NuGet Packages with .net\" class=\"alignnone size-medium wp-image-27915\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/7-min.png 1100w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/7-min-300x144.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/7-min-1024x491.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/7-min-768x368.png 768w\" sizes=\"auto, (max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<h2>Create SQL Database and Table.<\/h2>\n<p>Moving to the next section of the Web API in .NET 6.0 Tutorial, create New Database <strong>ProductDB<\/strong> in SQL, and execute the below script to create a <strong>Product<\/strong> table.<\/p>\n<pre>USE [ProductDB]\r\nGO\r\n\r\nSET ANSI_NULLS ON\r\nGO\r\n\r\nSET QUOTED_IDENTIFIER ON\r\nGO\r\n\r\nCREATE TABLE [dbo].[Products](\r\n\t[Id] [int] IDENTITY(1,1) NOT NULL,\r\n\t[Name] [varchar](50) NOT NULL,\r\n\t[Description] [varchar](250) NULL,\r\n\t[Price] [decimal](18, 2) NOT NULL,\r\nPRIMARY KEY CLUSTERED \r\n(\r\n\t[Id] ASC\r\n)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]\r\n) ON [PRIMARY]\r\nGO<\/pre>\n<h2>Create DB Context and Model <\/h2>\n<p>Now, let&#8217;s move on to the next step of our web API tutorial, where we will create the DBContext and Model.<\/p>\n<p>We are using the database first approach of entity framework.<br \/>\nWe have created a database table, and using the Scaffold-DbContext command of the entity framework; we will create the required class in the C# project.<\/p>\n<p>Open <strong>Package Manager Consol<\/strong> (Tool => Package Manager => Package Manager Consol) and run below command:<\/p>\n<pre>Scaffold-DbContext \"Server=SERVERNAME;Database=ProductDB;Integrated Security=True\" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models<\/pre>\n<p>Replace <mark><strong>SERVERNAME<\/strong><\/mark> with your database server name.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1100\" height=\"544\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/8-min.png\" alt=\"Create DB Context and Model with .net\" class=\"alignnone size-medium wp-image-27916\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/8-min.png 1100w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/8-min-300x148.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/8-min-1024x506.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/8-min-768x380.png 768w\" sizes=\"auto, (max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<p>Once this command is executed, the Model folder is created in the project solution. Model folder contains two files, <strong>ProductDBContext.cs<\/strong> and <strong>Product.cs. <\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1100\" height=\"528\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/9-min.png\" alt=\"Create DB Context and Model with .net\" class=\"alignnone size-medium wp-image-27917\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/9-min.png 1100w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/9-min-300x144.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/9-min-1024x492.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/9-min-768x369.png 768w\" sizes=\"auto, (max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<p><strong>ProductDBContext.cs <\/strong>is responsible for database interaction, and <strong>Product.cs<\/strong> is a model of the Products table.<\/p>\n<p>Remove <strong>OnConfiguring()<\/strong> method from ProductDBContext.cs; it contains a database connection string and is not a good practice. We will add the connection string in the appsettings.json file. <\/p>\n<p>Also remove <strong>ProductDBContext()<\/strong> constructor from this file. <\/p>\n<p class=\"boxed bg--secondary\" style=\"border: 1px solid #c7c7c7; box-shadow: 0 0 40px rgba(0, 0, 0, 0.2);\"><strong><i><span style=\"font-size:22px; color:#000;\">Build a .NET application is easier and hustle-free with Bacancy!<\/span><br \/>\nHire <a href=\"https:\/\/www.bacancytechnology.com\/hire-dot-net-developer\" target=\"_blank\" rel=\"noopener\">NET developer<\/a> who will help you meet your project requirements efficiently with commendable problem-solving skills.<\/i><\/strong><\/p>\n<h2>Configure DB Connection<\/h2>\n<p>Add database connection string in <strong>appsettings.json <\/strong>file.<\/p>\n<pre>{\r\n  \"Logging\": {\r\n    \"LogLevel\": {\r\n      \"Default\": \"Information\",\r\n      \"Microsoft.AspNetCore\": \"Warning\"\r\n    }\r\n  },\r\n  \"AllowedHosts\": \"*\",\r\n  \"ConnectionStrings\": {\r\n    \"ProductDB\": \"Server=SERVERNAME;Database=ProductDB;Integrated Security=True;\"\r\n  }\r\n}<\/pre>\n<p>Replace <strong>SERVERNAME<\/strong> with your database server name.<\/p>\n<p>As we are using the .Net 6 version, we need to make the required configuration changes in <strong>Program.cs<\/strong> file. Microsoft eliminates <strong>Startup.cs<\/strong> in .Net 6. In the previous .Net version, <strong>Startup.cs<\/strong> was used for configurations.<\/p>\n<p>Add below lines in <strong>Program.cs.<\/strong> Please refer to the below image for this.<\/p>\n<pre>var connectionString = builder.Configuration.GetConnectionString(\"ProductDB\");\r\nbuilder.Services.AddDbContextPool<ProductDBContext>(option =>\r\noption.UseSqlServer(connectionString)\r\n);<\/pre>\n<p>Also, add the below lines at the top of the <strong>Program.cs.<\/strong><\/p>\n<pre>using Microsoft.EntityFrameworkCore;\r\nusing ProductAPI.Models;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1100\" height=\"317\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/10-min.png\" alt=\"Configure DB Connection with .net\" class=\"alignnone size-medium wp-image-27918\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/10-min.png 1100w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/10-min-300x86.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/10-min-1024x295.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/10-min-768x221.png 768w\" sizes=\"auto, (max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<h2>Add Products Controller<\/h2>\n<p>Add a new empty API controller <strong>ProductsController.cs<\/strong> under the controller folder.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1100\" height=\"531\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/11-min.png\" alt=\"Add Products Controller with .net\" class=\"alignnone size-medium wp-image-27919\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/11-min.png 1100w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/11-min-300x145.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/11-min-1024x494.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/11-min-768x371.png 768w\" sizes=\"auto, (max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1100\" height=\"527\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/12-min.png\" alt=\"Add Products Controller with .net\" class=\"alignnone size-medium wp-image-27920\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/12-min.png 1100w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/12-min-300x144.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/12-min-1024x491.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/12-min-768x368.png 768w\" sizes=\"auto, (max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<p class=\"boxed bg--secondary\" style=\"border: 1px solid #c7c7c7; box-shadow: 0 0 40px rgba(0, 0, 0, 0.2);\"><strong><i><span style=\"font-size:22px; color:#000;\">Bacancy is not an option. Bacancy is a reliable choice!<\/span><br \/>\nAre you looking for a leading <a href=\"https:\/\/www.bacancytechnology.com\/net-development-company\" target=\"_blank\" rel=\"noopener\">NET development company<\/a> to develop your dream product? We are here for you! Trust your choice. Connect Now!<\/i><\/strong><\/p>\n<h2>Add Methods in ProductsController<\/h2>\n<p>In <strong>ProductsController.cs,<\/strong> we will add GET, POST, PUT, and DELETE endpoints to achieve CRUD operations. <\/p>\n<p>Please use the below code in your <strong>ProductsController.cs.<\/strong><\/p>\n<h2>Launch API<\/h2>\n<p>Finally, we are done with Web API in .NET 6.0 tutorial. Now, it\u2019s time to launch this API, press F5. As we are using Swagger UI, we can execute API directly.<\/p>\n<p>We can see GET, POST, PUT AND DELETE under Products. We can execute different API methods from this page itself.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1100\" height=\"529\" src=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/13-min.png\" alt=\"Launch API with .net\" class=\"alignnone size-medium wp-image-27921\" srcset=\"https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/13-min.png 1100w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/13-min-300x144.png 300w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/13-min-1024x492.png 1024w, https:\/\/www.bacancytechnology.com\/blog\/wp-content\/uploads\/2022\/06\/13-min-768x369.png 768w\" sizes=\"auto, (max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<h2>Github Repository: Web API in .NET 6.0 Example<\/h2>\n<p>Here\u2019s the <a href=\"https:\/\/github.com\/hardiknpatelhnp\/ProductCRUDAPI\" target=\"_blank\" rel=\"noopener\">source code<\/a> of Web API in .NET 6.0 example. Feel free to clone the repository and play around with the code. Start developing your demo application and learn how to build a CRUD operation.<\/p>\n<h2>Conclusion<\/h2>\n<p>So, this was all about how to develop Web API in .NET 6.0. I hope the tutorial helped you to begin with building a basic CRUD operation application using .NET. If you have any questions or feedback, feel free to contact us. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In this tutorial, we will build .NET 6 Web API that uses Entity Framework and SQL to create API endpoints. It will allow clients to perform CRUD operations in API on the data stored in the database. In our demo application, we will be using the database first approach. We will start with creating [&hellip;]<\/p>\n","protected":false},"author":105,"featured_media":27934,"comment_status":"open","ping_status":"open","sticky":false,"template":"blog-new-template.php","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"_lmt_disableupdate":"no","_lmt_disable":"","footnotes":""},"categories":[57],"tags":[],"coauthors":[1942],"class_list":["post-27894","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dot-net"],"acf":[],"modified_by":"Binal Prajapati","_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/posts\/27894","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/users\/105"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/comments?post=27894"}],"version-history":[{"count":0,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/posts\/27894\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/media\/27934"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=27894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=27894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=27894"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/blog\/wp-json\/wp\/v2\/coauthors?post=27894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}