<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>DotNet Core Mastery: Unraveling Basics to Advanced Techniques Archives - Coding Tutorial</title>
	<atom:link href="https://codingizfun.com/category/dotnet-interview-questions-topics/dotnet-core-mastery-unraveling-basics-toadvanced-techniques/feed/" rel="self" type="application/rss+xml" />
	<link>https://codingizfun.com/category/dotnet-interview-questions-topics/dotnet-core-mastery-unraveling-basics-toadvanced-techniques/</link>
	<description>Software Architecture and javascript concepts explained in detail with examples</description>
	<lastBuildDate>Sun, 25 Feb 2024 01:03:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.1</generator>
<site xmlns="com-wordpress:feed-additions:1">214557465</site>	<item>
		<title>Unveiling .NET Core: Introduction</title>
		<link>https://codingizfun.com/unveiling-net-core-introduction/</link>
					<comments>https://codingizfun.com/unveiling-net-core-introduction/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 25 Feb 2024 01:03:45 +0000</pubDate>
				<category><![CDATA[DotNet Core Mastery: Unraveling Basics to Advanced Techniques]]></category>
		<guid isPermaLink="false">https://codingizfun.com/?p=152</guid>

					<description><![CDATA[<p>Welcome to the World of .NET Core! Embark on an exciting journey into the realm of .NET Core! Before we dive into the technicalities, let&#8217;s take a quick stroll through the history of .NET and uncover details about .NET Core introduction. .NET, a robust framework crafted by Microsoft, has been a stalwart in software development....</p>
<p>The post <a href="https://codingizfun.com/unveiling-net-core-introduction/">Unveiling .NET Core: Introduction</a> appeared first on <a href="https://codingizfun.com">Coding Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Welcome to the World of .NET Core!</h2>



<p class="">Embark on an exciting journey into the realm of .NET Core! Before we dive into the technicalities, let&#8217;s take a quick stroll through the history of .NET and uncover details about .NET Core introduction.</p>



<p class="">.NET, a robust framework crafted by Microsoft, has been a stalwart in software development. As technology evolved, a demand for a more adaptable, cross-platform solution arose. This demand gave birth to .NET Core, a framework designed to meet the dynamic needs of modern development. </p>



<h2 class="wp-block-heading">Unlocking .NET Core&#8217;s Power: Key Features and Advantages</h2>



<p class="">Now, let&#8217;s unravel the fascinating features that set .NET Core apart.</p>



<ul class="wp-block-list">
<li class=""><strong>Cross-Platform Flexibility:</strong>&nbsp;Build and run dotnet applications on Windows, macOS, and Linux.</li>



<li class=""><strong>Open-Source Transparency:</strong>&nbsp;With the source code available to everyone, .NET Core promotes transparency and encourages community contributions.</li>



<li class=""><strong>Modular:</strong>&nbsp;.NET Core&#8217;s modular architecture empowers developers to pick only the components needed.</li>
</ul>



<h2 class="wp-block-heading">Contrasting .NET Core with the Traditional .NET Framework</h2>



<p class="">Let&#8217;s compare the innovative .NET Core and the traditional .NET Framework.</p>



<ul class="wp-block-list">
<li class=""><strong>Cross-Platform Prowess:</strong>&nbsp;While .NET Core effortlessly spans Windows, macOS, and Linux, the .NET Framework primarily caters to Windows.</li>



<li class=""><strong>Open-Source Collaboration:</strong>&nbsp;.NET Core embraces an open-source ethos, fostering community collaboration, while the .NET Framework relies heavily on Microsoft&#8217;s development.</li>



<li class=""><strong>Modularity vs. Monolith:</strong> .NET Core&#8217;s modular design allows component selection, whereas the .NET Framework operates as a monolithic entity.</li>



<li class=""><strong>Ability to house multiplt dotnet versions: </strong>In .NET Core, projects can independently specify and switch between different SDK versions using SDK-style projects and the <code>global.json</code> file. This flexibility contrasts with .NET Framework, where SDK versions are determined system-wide, making it less adaptable for projects with varying SDK requirements.</li>
</ul>



<h2 class="wp-block-heading">Hands-On Adventure: Crafting a &#8220;Hello World&#8221; Application</h2>



<p class="">Let&#8217;s get our hands dirty and create a simple yet impactful &#8220;Hello World&#8221; application.</p>



<ol class="wp-block-list">
<li class=""><strong>Install .NET Core SDK:</strong>&nbsp;Set the stage by installing the .NET Core Software Development Kit.</li>



<li class=""><strong>Open a Terminal or Command Prompt:</strong>&nbsp;It&#8217;s your gateway to the world of coding.</li>



<li class=""><strong>Create a Console Masterpiece:</strong>&nbsp;Execute the magic command, dotnet new console -n HelloWorld, or leverage the user-friendly Visual Studio editor.</li>



<li class=""><strong>Navigate to the HelloWorld Directory:</strong>&nbsp;Dive into your newly created project with cd HelloWorld.</li>



<li class=""><strong>Run the Application:</strong>&nbsp;Witness the magic unfold with dotnet run.</li>
</ol>



<p class="">Congratulations! You&#8217;ve taken the first steps into the exciting universe of .NET Core. Keep the momentum going, and in the next leg of our journey, we&#8217;ll explore even more captivating concepts and practical applications.</p>



<p class="">Ready to delve deeper? Stay tuned for the next post in our .NET Core series!</p>



<p class=""><strong>References:</strong></p>



<p class=""><a href="https://learn.microsoft.com/en-us/archive/msdn-magazine/2017/september/net-standard-demystifying-net-core-and-net-standard">https://learn.microsoft.com/en-us/archive/msdn-magazine/2017/september/net-standard-demystifying-net-core-and-net-standard</a></p>
<p>The post <a href="https://codingizfun.com/unveiling-net-core-introduction/">Unveiling .NET Core: Introduction</a> appeared first on <a href="https://codingizfun.com">Coding Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codingizfun.com/unveiling-net-core-introduction/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">152</post-id>	</item>
		<item>
		<title>Minimal API</title>
		<link>https://codingizfun.com/minimal-api/</link>
					<comments>https://codingizfun.com/minimal-api/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 19 Aug 2023 23:27:43 +0000</pubDate>
				<category><![CDATA[DotNet Core Mastery: Unraveling Basics to Advanced Techniques]]></category>
		<guid isPermaLink="false">https://codingizfun.com/?p=126</guid>

					<description><![CDATA[<p>What is Minimal API? .NET Core Minimal API was introduced with .NET 6 to simplify creating focused APIs. These APIs reduce setup complexity by fluently declaring routes and actions, bypassing traditional scaffolding and controller overhead. While conventional API setup involves controllers, routes, and middleware, Minimal APIs use concise syntax. They accommodate scaling, handling complex routing,...</p>
<p>The post <a href="https://codingizfun.com/minimal-api/">Minimal API</a> appeared first on <a href="https://codingizfun.com">Coding Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">What is Minimal API?</h2>



<p>.NET Core Minimal API was introduced with .NET 6 to simplify creating focused APIs. These APIs reduce setup complexity by fluently declaring routes and actions, bypassing traditional scaffolding and controller overhead.</p>



<p>While conventional API setup involves controllers, routes, and middleware, Minimal APIs use concise syntax. They accommodate scaling, handling complex routing, authorization, and content control.</p>



<p>Core features include:</p>



<ol class="wp-block-list">
<li><strong>Simplicity:</strong>&nbsp;Syntax is concise, reducing setup compared to MVC-based APIs.</li>



<li><strong>No Controllers:</strong>&nbsp;Avoid separate controllers; declare routes and handlers directly.</li>



<li><strong>Single File:</strong>&nbsp;Suitable for small APIs, fit the entire API within a single file.</li>



<li><strong>Inline Configuration:</strong>&nbsp;Define configuration inline for intuitive setup.</li>



<li><strong>Convention-Based:</strong>&nbsp;Reduce explicit configuration needs.</li>
</ol>



<h2 class="wp-block-heading">Advantages:</h2>



<ol class="wp-block-list">
<li><strong>Simplicity:</strong>&nbsp;Readable syntax aids understanding.</li>



<li><strong>Reduced Boilerplate:</strong>&nbsp;Less code, quicker development.</li>



<li><strong>Inline Configuration:</strong>&nbsp;Intuitive settings, simple scenarios.</li>



<li><strong>Single File:</strong>&nbsp;Manageable for small projects and prototypes.</li>



<li><strong>Quick Prototyping:</strong>&nbsp;Ideal for fast microservices development.</li>
</ol>



<h2 class="wp-block-heading">Disadvantages:</h2>



<ol class="wp-block-list">
<li><strong>Limited Flexibility:</strong>&nbsp;May not suit complex projects if not well designed.</li>



<li><strong>Scalability and Maintainability:</strong>&nbsp;Better for simple cases.</li>



<li><strong>Testing and Separation:</strong>&nbsp;Effort needed for concerns separation.</li>



<li><strong>Learning Curve:</strong>&nbsp;Adaptation for experienced developers.</li>
</ol>



<p>Now, let&#8217;s understand Minimal API with a practical TODO list example</p>



<h2 class="wp-block-heading">Building a Todo List API with .NET Core Minimal APIs: A Step-by-Step Guide</h2>



<p>Are you ready to dive into the world of API development using the power of .NET Core Minimal APIs? In this comprehensive guide, we&#8217;ll go through the process of building a Todo List API from scratch. By the end, you&#8217;ll have a clear understanding of each step and how Minimal APIs can streamline your development process.</p>



<h3 class="wp-block-heading">Step 1: Get Started with a New .NET Core Project</h3>



<h4 class="wp-block-heading">Creating a Minimal API using Command Prompt</h4>



<p>To kick things off, let&#8217;s create a new .NET Core project named &#8220;TodoApi&#8221; using the command-line interface:</p>



<p><code>dotnet new web -n TodoApi</code></p>



<p>This simple command sets up the foundation for our Todo List API project. </p>



<p>We can even create a new project using Visual Studio by following below steps.</p>



<h4 class="wp-block-heading">Creating a Minimal API with Visual Studio: Step-by-Step Guide</h4>



<ul class="wp-block-list">
<li>Open Visual Studio and click on &#8220;Create a New Project&#8221;  </li>
</ul>



<ul class="wp-block-list">
<li>Select &#8220;ASP.NET Core Web API&#8221; project templete as shown below and click on Next</li>
</ul>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="640" height="333" src="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image.png?resize=640%2C333&#038;ssl=1" alt="Minimal API" class="wp-image-129" srcset="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image.png?resize=1024%2C532&amp;ssl=1 1024w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image.png?resize=300%2C156&amp;ssl=1 300w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image.png?resize=768%2C399&amp;ssl=1 768w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image.png?resize=1536%2C798&amp;ssl=1 1536w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image.png?resize=850%2C441&amp;ssl=1 850w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image.png?w=1914&amp;ssl=1 1914w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image.png?w=1280&amp;ssl=1 1280w" sizes="(max-width: 640px) 100vw, 640px" data-recalc-dims="1" /></figure>



<ul class="wp-block-list">
<li>Enter a project name, choose a location, and click &#8220;Create.&#8221;</li>
</ul>



<figure class="wp-block-image size-large"><img decoding="async" width="640" height="339" src="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-1.png?resize=640%2C339&#038;ssl=1" alt="Minimal API" class="wp-image-130" srcset="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-1.png?resize=1024%2C542&amp;ssl=1 1024w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-1.png?resize=300%2C159&amp;ssl=1 300w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-1.png?resize=768%2C407&amp;ssl=1 768w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-1.png?resize=1536%2C813&amp;ssl=1 1536w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-1.png?resize=850%2C450&amp;ssl=1 850w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-1.png?w=1894&amp;ssl=1 1894w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-1.png?w=1280&amp;ssl=1 1280w" sizes="(max-width: 640px) 100vw, 640px" data-recalc-dims="1" /></figure>



<ul class="wp-block-list">
<li>In the next screen, we configure the Minimal API. Choose options such as HTTPS, OpenAPI support. Make sure to uncheck &#8220;Use Controllers (uncheck ro use minimal APIs)&#8221;. Click on Create. </li>
</ul>



<figure class="wp-block-image size-large"><img decoding="async" width="640" height="334" src="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-4.png?resize=640%2C334&#038;ssl=1" alt="Minimal API" class="wp-image-133" srcset="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-4.png?resize=1024%2C534&amp;ssl=1 1024w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-4.png?resize=300%2C156&amp;ssl=1 300w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-4.png?resize=768%2C400&amp;ssl=1 768w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-4.png?resize=1536%2C800&amp;ssl=1 1536w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-4.png?resize=850%2C443&amp;ssl=1 850w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-4.png?w=1900&amp;ssl=1 1900w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-4.png?w=1280&amp;ssl=1 1280w" sizes="(max-width: 640px) 100vw, 640px" data-recalc-dims="1" /></figure>



<h3 class="wp-block-heading">Step 2: Navigate to the Minimal API Project Directory</h3>



<p>Navigate to the project directory just created:</p>



<p><code>cd TodoApi</code></p>



<h3 class="wp-block-heading">Step 3: Define Your Todo Model</h3>



<p>Create <code>Models</code> folder within the project and create a file named <code>Todo.cs</code>. This is where you&#8217;ll define the structure of your todo items:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="640" height="306" src="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-6.png?resize=640%2C306&#038;ssl=1" alt="Minimal API" class="wp-image-135" srcset="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-6.png?resize=1024%2C489&amp;ssl=1 1024w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-6.png?resize=300%2C143&amp;ssl=1 300w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-6.png?resize=768%2C367&amp;ssl=1 768w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-6.png?resize=850%2C406&amp;ssl=1 850w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-6.png?w=1051&amp;ssl=1 1051w" sizes="(max-width: 640px) 100vw, 640px" data-recalc-dims="1" /></figure>



<p><code>Todo</code> model will hold essential information about each todo task, including an <code>Id</code>, <code>Title</code>, and <code>IsCompleted</code> flag.</p>



<h3 class="wp-block-heading">Step 4: Create the Minimal API</h3>



<p>Open the <code>Program.cs</code> file and add the following code before app.Run():</p>



<div class="wp-block-group has-light-green-cyan-background-color has-background"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<div class="wp-block-group has-very-light-gray-to-cyan-bluish-gray-gradient-background has-background"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<div class="wp-block-group has-background" style="background:radial-gradient(rgb(238,238,238) 0%,rgb(169,184,195) 100%)"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<p><strong>//Todo List Code</strong><br>var todos = new List();<br>int nextId = 1;</p>



<p><strong>// GET endpoint to retrieve the list of todos</strong><br>app.MapGet(&#8220;/todos&#8221;, () =&gt; todos);</p>



<p><strong>// POST endpoint to add a new todo</strong><br>app.MapPost(&#8220;/todos&#8221;, (Todo todo) =&gt; {<br>todo.Id = nextId++;<br>todos.Add(todo);<br>return todo;<br>});</p>



<p><strong>// PUT endpoint to update an existing todo</strong><br>app.MapPut(&#8220;/todos/{id}&#8221;, (int id, Todo updatedTodo) =&gt; {<br><strong>// Find the existing todo with the provided ID</strong><br>var existingTodo = todos.FirstOrDefault(t =&gt; t.Id == id);<br>if (existingTodo != null)<br>{<br><strong>// Update the title and completion status with the new values</strong><br>existingTodo.Title = updatedTodo.Title;<br>existingTodo.IsCompleted = updatedTodo.IsCompleted;<br>return Results.Ok(existingTodo);<br>}<br>return Results.NotFound();<strong>// Return &#8220;Not Found&#8221; if the todo doesn&#8217;t exist</strong><br>});</p>



<p><strong>// DELETE endpoint to remove a todo</strong><br>app.MapDelete(&#8220;/todos/{id}&#8221;, (int id) =&gt; {<br><strong>// Find the todo to remove based on the provided ID</strong><br>var todoToRemove = todos.FirstOrDefault(t =&gt; t.Id == id);</p>



<pre class="wp-block-code"><code>if (todoToRemove != null)
{
    todos.Remove(todoToRemove); <strong>// Remove the todo from the list</strong>
    return Results.Ok(); <strong>// Return "Ok" to indicate success</strong>
}

return Results.NotFound(); <strong>// Return "Not Found" if the todo doesn't exist</strong></code></pre>



<p>});</p>
</div></div>
</div></div>
</div></div>



<p>Let&#8217;s break it down:</p>



<div class="wp-block-group has-light-green-cyan-background-color has-background"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<aside class="wp-block-group"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<div class="wp-block-group has-very-light-gray-to-cyan-bluish-gray-gradient-background has-background"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<div class="wp-block-group has-background" style="background:radial-gradient(rgb(238,238,238) 0%,rgb(169,184,195) 100%)"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<p>using TodoApi.Models;</p>



<p>var builder = WebApplication.CreateBuilder(args);</p>



<p>var app = builder.Build();</p>



<p><strong>//Todo List Code</strong><br>var todos = new List();<br>int nextId = 1;</p>



<p><strong>// GET endpoint to retrieve the list of todos</strong><br>app.MapGet(&#8220;/todos&#8221;, () =&gt; todos);</p>
</div></div>
</div></div>
</div></div>
</div></aside>
</div></div>



<ul class="wp-block-list">
<li><code>WebApplication.CreateBuilder</code> initializes a builder for the web application.</li>



<li><code>builder.Build()</code> creates your application.</li>



<li>We set up an empty list named <code>todos</code> to hold your todo items.</li>



<li><code>nextId</code> helps manage the IDs for new todos.</li>



<li>We define a <code>GET</code> endpoint at <code>/todos</code> to retrieve your list of todos.</li>
</ul>



<p></p>



<p class="has-background" style="background:radial-gradient(rgb(238,238,238) 0%,rgb(169,184,195) 100%)"><strong>// POST endpoint to add a new todo</strong><br>app.MapPost(&#8220;/todos&#8221;, (Todo todo) =&gt; {<br>todo.Id = nextId++;<br>todos.Add(todo);<br>return todo;<br>});</p>



<p>In this block:</p>



<ul class="wp-block-list">
<li>We define a <code>POST</code> endpoint at <code>/todos</code> for adding new todos.</li>



<li>Each new todo is assigned a unique ID and added to the <code>todos</code> list.</li>



<li>The newly added todo is then returned as a response.</li>
</ul>



<p></p>



<p class="has-background" style="background:radial-gradient(rgb(238,238,238) 0%,rgb(169,184,195) 100%)"><strong>// PUT endpoint to update an existing todo</strong><br>app.MapPut(&#8220;/todos/{id}&#8221;, (int id, Todo updatedTodo) =&gt; {<br><strong>// Find the existing todo with the provided ID</strong><br>var existingTodo = todos.FirstOrDefault(t =&gt; t.Id == id);<br>if (existingTodo != null)<br>{<br><strong>// Update the title and completion status with the new values</strong><br>existingTodo.Title = updatedTodo.Title;<br>existingTodo.IsCompleted = updatedTodo.IsCompleted;<br>return Results.Ok(existingTodo);<br>}<br>return Results.NotFound();<strong>// Return &#8220;Not Found&#8221; if the todo doesn&#8217;t exist</strong><br>});</p>



<p>Now for the <code>PUT</code> endpoint:</p>



<ul class="wp-block-list">
<li>We define a <code>PUT</code> endpoint at <code>/todos/{id}</code> for updating existing todos.</li>



<li>We find the todo with the provided <code>id</code> in the <code>todos</code> list.</li>



<li>If the todo exists, we update its <code>Title</code> and <code>IsCompleted</code> properties based on the provided <code>updatedTodo</code> and return the updated todo.</li>



<li>If the todo doesn&#8217;t exist, a &#8220;Not Found&#8221; result is returned.</li>
</ul>



<p></p>



<div class="wp-block-group has-light-green-cyan-background-color has-background"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<div class="wp-block-group has-background" style="background:radial-gradient(rgb(238,238,238) 0%,rgb(169,184,195) 100%)"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<p><strong>// DELETE endpoint to remove a todo</strong><br>app.MapDelete(&#8220;/todos/{id}&#8221;, (int id) =&gt; {<br><strong>// Find the todo to remove based on the provided ID</strong><br>var todoToRemove = todos.FirstOrDefault(t =&gt; t.Id == id);</p>



<pre class="wp-block-code"><code>if (todoToRemove != null)
{
    todos.Remove(todoToRemove); <strong>// Remove the todo from the list</strong>
    return Results.Ok(); <strong>// Return "Ok" to indicate success</strong>
}

return Results.NotFound(); <strong>// Return "Not Found" if the todo doesn't exist</strong></code></pre>



<p>});</p>
</div></div>
</div></div>



<p>And finally, the <code>DELETE</code> endpoint:</p>



<ul class="wp-block-list">
<li>We define a <code>DELETE</code> endpoint at <code>/todos/{id}</code> for removing todos.</li>



<li>We locate the todo to remove in the <code>todos</code> list based on the provided <code>id</code>.</li>



<li>If the todo exists, we remove it from the list and return an &#8220;Ok&#8221; result to indicate success.</li>



<li>If the todo doesn&#8217;t exist, a &#8220;Not Found&#8221; result is returned.</li>
</ul>



<h3 class="wp-block-heading">Step 5: Run Your Application</h3>



<p>Time to see your Todo List API in action! Run the application with:</p>



<p><code>Run dotnet run</code> in command prompt or click on TodoApi in Visual Studio as highlighted below.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="640" height="218" src="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-7.png?resize=640%2C218&#038;ssl=1" alt="" class="wp-image-136" srcset="https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-7.png?resize=1024%2C349&amp;ssl=1 1024w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-7.png?resize=300%2C102&amp;ssl=1 300w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-7.png?resize=768%2C262&amp;ssl=1 768w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-7.png?resize=1536%2C523&amp;ssl=1 1536w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-7.png?resize=850%2C290&amp;ssl=1 850w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-7.png?w=1887&amp;ssl=1 1887w, https://i0.wp.com/codingizfun.com/wp-content/uploads/2023/08/image-7.png?w=1280&amp;ssl=1 1280w" sizes="(max-width: 640px) 100vw, 640px" data-recalc-dims="1" /></figure>



<h3 class="wp-block-heading">Step 6: Interact with Your Todo List API</h3>



<p>Here&#8217;s how you can interact with your Todo List API:</p>



<ul class="wp-block-list">
<li><strong>GET</strong> <code>/todos</code>: Retrieve the list of todos.</li>



<li><strong>POST</strong> <code>/todos</code>: Add a new todo.</li>



<li><strong>PUT</strong> <code>/todos/{id}</code>: Update an existing todo.</li>



<li><strong>DELETE</strong> <code>/todos/{id}</code>: Delete a todo.</li>
</ul>



<p>Congratulations! You&#8217;ve successfully built a Todo List API using .NET Core Minimal APIs. This guide took you through the process step by step and provided sample code for each stage.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p>By following this comprehensive guide, you&#8217;ve unlocked the power of .NET Core Minimal APIs to create a functional Todo List API. This step-by-step journey, complete with detailed explanations and code samples, will equip you with the knowledge you need to craft your own APIs efficiently. This code can further be enhanced by adding Repositories and other functinalilties based on requirement.</p>



<p>If you like this post and are interested to learn more about MInimal API, please go through below links for other related posts</p>



<p><a href="https://codingizfun.com/category/dotnet-interview-questions/dotnet-core-interview-questions/minimal-api/">Minimal API Archives &#8211; Coding Tutorial (codingizfun.com)</a></p>



<h2 class="wp-block-heading">References</h2>



<p><a href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/overview?view=aspnetcore-7.0">https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/overview?view=aspnetcore-7.0</a></p>



<p><a href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-7.0">https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-7.0</a></p>



<p></p>
<p>The post <a href="https://codingizfun.com/minimal-api/">Minimal API</a> appeared first on <a href="https://codingizfun.com">Coding Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codingizfun.com/minimal-api/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">126</post-id>	</item>
	</channel>
</rss>
