{"id":66646,"date":"2022-03-01T07:30:20","date_gmt":"2022-03-01T06:30:20","guid":{"rendered":"https:\/\/drafts.code-maze.com\/?p=66646"},"modified":"2025-04-25T11:50:10","modified_gmt":"2025-04-25T09:50:10","slug":"dotnet-minimal-api","status":"publish","type":"post","link":"https:\/\/code-maze.com\/dotnet-minimal-api\/","title":{"rendered":"Minimal APIs in .NET 6"},"content":{"rendered":"<p>In this article, we are going to explain the core idea and basic concepts of the minimal APIs in .NET 6. But if we try to explain it in one sentence, it will be that it is an API without the need for a controller.<\/p>\n<p>Other than a theoretical explanation, we are going to dive into the code and show how we can implement a minimal API that has all CRUD operations.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/aspnetcore-webapi\/Minimal%20API\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let&#8217;s start.<\/p>\n<h2>The Origin of the Minimal APIs<\/h2>\n<p>The story of the minimal API started in November 2019. The developer community got a chance to see the implementation of the <a href=\"https:\/\/x.com\/markrendle\/status\/1198324914102636545\" target=\"_blank\" rel=\"nofollow noopener\">distributed calculator<\/a> in Go, Python, C#, and Javascript. When the community started comparing how many files and lines of code are needed to do almost the same thing with C# compared to other languages, it was apparent that C# seems more complicated than the rest of them.<\/p>\n<p>Imagine the number of concepts and features accumulated over the years and how overwhelming it might be for a newcomer to dig into the world of .NET web development. Therefore, a .NET Core team wanted to reduce the complexity for all developers (newcomers and veterans) and embrace minimalism. So if we&#8217;re going to create a simple API with a single endpoint, we should be able to do it within a single file. But if we need to switch later to use controllers again, we should also be able to do that.<\/p>\n<p>Let&#8217;s see what they have accomplished.<\/p>\n<h2>How to Setup Minimal APIs?<\/h2>\n<p>We need to have <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/#download\" target=\"_blank\" rel=\"nofollow noopener\">Visual Studio 2022<\/a> with the ASP.NET and web development workload to follow along with this article.<\/p>\n<p>To create a minimal API, we are going to create a C# project from the ASP.NET Core Empty template and uncheck all the checkboxes in the additional information dialog. Doing that, we are going to end up with the <code>Program<\/code> class with four lines in it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var builder = WebApplication.CreateBuilder(args);\r\nvar app = builder.Build();\r\n\r\napp.MapGet(\"\/\", () =&gt; \"Hello World!\");\r\n\r\napp.Run();<\/pre>\n<p>And that&#8217;s it. Once we run our app, we will see the <code>Hello Word!<\/code> message in a browser.<\/p>\n<p>Let&#8217;s explain how it is possible to have an API with one endpoint up and running with four lines of code.<\/p>\n<p>The first thing we can notice is missing <code>using<\/code> directives. C#10 introduced global <code>using<\/code> directives, and the common ones are included by default if the feature is enabled. Since one of them is <code>Microsoft.AspNetCore.Builder<\/code> we don&#8217;t need to write anything.<\/p>\n<p>Then we can see <code>MapGet<\/code>, an extension method from the <code>EndpointRouteBuilderExtensions<\/code> class that accepts a delegate as one of the parameters. Accepting any delegate is another example where C#10 put minimal API at its best. We can pass any method to the <code>MapGet<\/code> method, and the compiler will do its best to figure out how to convert it to the <code>RequestDelegate<\/code>. If it can&#8217;t, it will let us know.<\/p>\n<p>Lastly, with the <code>app.Run()<\/code> method, we are able to run our app.<\/p>\n<h3>How Does Dependency Injection Work With the Minimal APIs?<\/h3>\n<p>A new feature in the <a href=\"https:\/\/code-maze.com\/dependency-injection-aspnet\/\" target=\"_blank\" rel=\"noopener\">dependency injection<\/a> (DI) container in the .NET 6 enables us to know which type is registered as a resolvable type in the container. That means we can amend a delegate in the <code>MapGet<\/code> method with some types that we have registered with the DI without the need for additional attributes or injections via constructors. For example, we can write:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">app.MapGet(\"\/\", (IHttpClientFactory httpClientFactory) =&gt;\u00a0 \"Hello World!\"));<\/code><\/p>\n<p>And the framework will know that <code>IHttpClientFactory<\/code> is registered as a resolvable type. It can visit the DI container and populate it with the registered type. This was not possible before .NET 6.<\/p>\n<h2>Implementation of the CRUD Methods in the Minimal APIs<\/h2>\n<p>For this example, we are going to use the <a href=\"https:\/\/code-maze.com\/entity-framework-core-series\/\" target=\"_blank\" rel=\"noopener\">Entity Framework Core<\/a> in-memory database. You can find a detailed setup in the <a href=\"https:\/\/code-maze.com\/aspnetcore-creating-multiple-resources-with-single-request\/\" target=\"_blank\" rel=\"noopener\">Creating Multiple Resources with a Single Request in ASP.NET Core<\/a> article.<\/p>\n<p>Since we are going to operate on articles, let&#8217;s create an <code>Article<\/code> class:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public class Article\r\n{\r\n    public int Id { get; set; }\r\n\r\n    public string? Title { get; set; }\r\n\r\n    public string? Content { get; set; }\r\n\r\n    public DateTime? PublishedAt { get; set; }\r\n}<\/pre>\n<p>And an <code>ArticleRequest<\/code> record:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public record ArticleRequest(string? Title, string? Content, DateTime? PublishedAt);<\/code><\/p>\n<p>Let&#8217;s first implement get methods and explain what&#8217;s happening:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">app.MapGet(\"\/articles\", async (ApiContext context) =&gt; Results.Ok(await context.Articles.ToListAsync()));\r\n\r\napp.MapGet(\"\/articles\/{id}\", async (int id, ApiContext context) =&gt;\r\n{\r\n    var article = await context.Articles.FindAsync(id);\r\n\r\n    return article != null ? Results.Ok(article) : Results.NotFound();\r\n});<\/pre>\n<p>For both methods, we add the route pattern as a first parameter. In the first <code>MapGet<\/code> implementation <code>ApiContext<\/code> is resolved in the delegate because it is registered as a resolvable type. In the second <code>MapGet<\/code> implementation, we add <code>id<\/code> as an additional parameter in the delegate. We could also change the order of the parameters:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-highlight=\"1\">app.MapGet(\"\/articles\/{id}\", async (ApiContext context, int id) =&gt;\r\n{\r\n    var article = await context.Articles.FindAsync(id);\r\n    return article != null ? Results.Ok(article) : Results.NotFound();\r\n});<\/pre>\n<p>And everything will continue to work. That is that nifty feature where the compiler tries to resolve any delegate as a <code>RequestDelegate<\/code>, and it is doing a pretty good job.<\/p>\n<p>To continue, let&#8217;s implement POST and DELETE methods:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">app.MapPost(\"\/articles\", async (ArticleRequest article, ApiContext context) =&gt;\r\n{\r\n    var createdArticle = context.Articles.Add(new Article\r\n    {\r\n        Title = article.Title ?? string.Empty, \r\n        Content = article.Content ?? string.Empty,\r\n        PublishedAt = article.PublishedAt,\r\n    });\r\n\r\n    await context.SaveChangesAsync();\r\n\r\n    return Results.Created($\"\/articles\/{createdArticle.Entity.Id}\", createdArticle.Entity);\r\n});\r\n\r\napp.MapDelete(\"\/articles\/{id}\", async (int id, ApiContext context) =&gt;\r\n{\r\n    var article = await context.Articles.FindAsync(id);\r\n\r\n    if (article == null)\r\n    {\r\n        return Results.NotFound();\r\n    }\r\n\r\n    context.Articles.Remove(article);\r\n\r\n    await context.SaveChangesAsync();\r\n\r\n    return Results.NoContent();\r\n});<\/pre>\n<p>Finally, we are going to implement the PUT method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">app.MapPut(\"\/articles\/{id}\", async (int id, ArticleRequest article, ApiContext context) =&gt;\r\n{\r\n    var articleToUpdate = await context.Articles.FindAsync(id);\r\n \r\n    if (articleToUpdate == null)\r\n        return Results.NotFound();\r\n\r\n    if (article.Title != null)\r\n        articleToUpdate.Title = article.Title;\r\n\r\n    if (article.Content != null)\r\n        articleToUpdate.Content = article.Content;\r\n\r\n    if (article.PublishedAt != null)\r\n        articleToUpdate.PublishedAt = article.PublishedAt;\r\n\r\n    await context.SaveChangesAsync();\r\n\r\n    return Results.Ok(articleToUpdate);\r\n});<\/pre>\n<p>Since we want to focus on Minimal APIs our implementation is simple and it is missing proper request model validations or using mapping with <a href=\"https:\/\/code-maze.com\/automapper-net-core\/\" target=\"_blank\" rel=\"noopener\">AutoMapper<\/a>. You can read how to apply all these properly in our <a href=\"https:\/\/code-maze.com\/net-core-web-development-part6\/\" target=\"_blank\" rel=\"noopener\">ASP.NET Core Web API \u2013 Post, Put, Delete<\/a> article.<\/p>\n<p>Interestingly, there isn&#8217;t an extension method <code>MapPatch<\/code> in the <code>EndpointRouteBuilderExtensions<\/code> class. But we can use <code>MapMethods<\/code> method that is more robust and adaptable than the previous ones:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">app.MapMethods(\"\/articles\/{id}\", new[] { \"PATCH\" }, async (int id, ArticleRequest article, ApiContext context) =&gt; { ... });<\/code><\/p>\n<p>If you want to implement the PATCH method in the right way, you can read more about it in our <a href=\"https:\/\/code-maze.com\/using-httpclient-to-send-http-patch-requests-in-asp-net-core\/\" target=\"_blank\" rel=\"noopener\">Using HttpClient to Send HTTP PATCH Requests in ASP.NET Core<\/a> article.<\/p>\n<h3>How to Use Swagger, Authentication, and Authorization?<\/h3>\n<p>The great thing is that there isn&#8217;t any real difference in how to set up and use Swagger in the Minimal APIs than before. You can read more about Swagger, and how to configure it in our <a href=\"https:\/\/code-maze.com\/swagger-ui-asp-net-core-web-api\/\" target=\"_blank\" rel=\"noopener\">Configuring and Using Swagger UI in ASP.NET Core Web API<\/a>\u00a0article.<\/p>\n<p>The same goes for authentication and authorization. The only new feature is adding the authentication and authorization attributes (or any attribute) to the delegate methods. That was not possible in the older versions of the C#. So if we would implement authentication as in our <a href=\"https:\/\/code-maze.com\/authentication-aspnetcore-jwt-1\/\" target=\"_blank\" rel=\"noopener\">ASP.NET Core Authentication with JWT<\/a> article, we could add <code>[Authorize]<\/code> attribute on our delegates:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">app.MapPut(\"\/articles\/{id}\", [Authorize] async (int id, ArticleRequest article, ApiContext context) =&gt; { ... }<\/code><\/p>\n<h2>Organizing the Code in Minimal APIs<\/h2>\n<p>With minimal APIs the\u00a0 <code>Program<\/code> class can become quite large with a lot of code lines. To avoid that, let&#8217;s show how we can organize our code.<\/p>\n<p>We are going to extract the code within each mapping method into a separate\u00a0<code>ArticleService<\/code> class that is going to implement\u00a0<code>IArticleService<\/code> interface (you can find the implementation in our source code). And then, since we can inject our service into delegate methods we can change our code to:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-highlight=\"4,8-21\">var builder = WebApplication.CreateBuilder(args);\r\n\r\nbuilder.Services.AddDbContext(opt =&gt; opt.UseInMemoryDatabase(\"api\"));\r\nbuilder.Services.AddScoped&lt;IArticleService, ArticleService&gt;();\r\n\r\nvar app = builder.Build();\r\n\r\napp.MapGet(\"\/articles\", async (IArticleService articleService) \r\n    =&gt; await articleService.GetArticles());\r\n\r\napp.MapGet(\"\/articles\/{id}\", async (int id, IArticleService articleService) \r\n    =&gt; await articleService.GetArticleById(id));\r\n\r\napp.MapPost(\"\/articles\", async (ArticleRequest articleRequest, IArticleService articleService) \r\n    =&gt; await articleService.CreateArticle(articleRequest));\r\n\r\napp.MapPut(\"\/articles\/{id}\", async (int id, ArticleRequest articleRequest, IArticleService articleService) \r\n    =&gt; await articleService.UpdateArticle(id, articleRequest));\r\n\r\napp.MapDelete(\"\/articles\/{id}\", async (int id, IArticleService articleService) \r\n    =&gt; await articleService.DeleteArticle(id));\r\n\r\napp.Run();<\/pre>\n<p>Our <code>Program<\/code> class looks more organized now. We could further extract all mapping calls to a separate extension method, but with each refactor, we are diverging from the original idea of the minimal APIs to be straightforward.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, we&#8217;ve talked about minimal API origin and its motivation to exist. We also have shown how to create minimal API with CRUD operations.\u00a0<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we are going to explain the core idea and basic concepts of the minimal APIs in .NET 6. But if we try to explain it in one sentence, it will be that it is an API without the need for a controller. Other than a theoretical explanation, we are going to dive [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":62187,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[12,171],"tags":[79,1066],"class_list":["post-66646","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","category-http","tag-asp-net-core","tag-minimal-api","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Minimal APIs in .NET 6 - Code Maze<\/title>\n<meta name=\"description\" content=\"In this article, we are going to explain the core idea and basic concepts of the minimal APIs in .NET 6 with examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/dotnet-minimal-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Minimal APIs in .NET 6 - Code Maze\" \/>\n<meta property=\"og:description\" content=\"In this article, we are going to explain the core idea and basic concepts of the minimal APIs in .NET 6 with examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/dotnet-minimal-api\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-01T06:30:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-25T09:50:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Code Maze\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Code Maze\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/dotnet-minimal-api\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/dotnet-minimal-api\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"Minimal APIs in .NET 6\",\"datePublished\":\"2022-03-01T06:30:20+00:00\",\"dateModified\":\"2025-04-25T09:50:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/dotnet-minimal-api\/\"},\"wordCount\":1126,\"commentCount\":7,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/dotnet-minimal-api\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\",\"keywords\":[\"asp.net core\",\"Minimal API\"],\"articleSection\":[\"C#\",\"HTTP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/dotnet-minimal-api\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/dotnet-minimal-api\/\",\"url\":\"https:\/\/code-maze.com\/dotnet-minimal-api\/\",\"name\":\"Minimal APIs in .NET 6 - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/dotnet-minimal-api\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/dotnet-minimal-api\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\",\"datePublished\":\"2022-03-01T06:30:20+00:00\",\"dateModified\":\"2025-04-25T09:50:10+00:00\",\"description\":\"In this article, we are going to explain the core idea and basic concepts of the minimal APIs in .NET 6 with examples.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/dotnet-minimal-api\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/dotnet-minimal-api\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/dotnet-minimal-api\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png\",\"width\":1100,\"height\":620,\"caption\":\"ASP.NET Core\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/dotnet-minimal-api\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Minimal APIs in .NET 6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\",\"name\":\"Code Maze\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"caption\":\"Code Maze\"},\"description\":\"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/codemaze\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/codemazecontributor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Minimal APIs in .NET 6 - Code Maze","description":"In this article, we are going to explain the core idea and basic concepts of the minimal APIs in .NET 6 with examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/dotnet-minimal-api\/","og_locale":"en_US","og_type":"article","og_title":"Minimal APIs in .NET 6 - Code Maze","og_description":"In this article, we are going to explain the core idea and basic concepts of the minimal APIs in .NET 6 with examples.","og_url":"https:\/\/code-maze.com\/dotnet-minimal-api\/","og_site_name":"Code Maze","article_published_time":"2022-03-01T06:30:20+00:00","article_modified_time":"2025-04-25T09:50:10+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","type":"image\/png"}],"author":"Code Maze","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Code Maze","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/dotnet-minimal-api\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/dotnet-minimal-api\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"Minimal APIs in .NET 6","datePublished":"2022-03-01T06:30:20+00:00","dateModified":"2025-04-25T09:50:10+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/dotnet-minimal-api\/"},"wordCount":1126,"commentCount":7,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/dotnet-minimal-api\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","keywords":["asp.net core","Minimal API"],"articleSection":["C#","HTTP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/dotnet-minimal-api\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/dotnet-minimal-api\/","url":"https:\/\/code-maze.com\/dotnet-minimal-api\/","name":"Minimal APIs in .NET 6 - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/dotnet-minimal-api\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/dotnet-minimal-api\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","datePublished":"2022-03-01T06:30:20+00:00","dateModified":"2025-04-25T09:50:10+00:00","description":"In this article, we are going to explain the core idea and basic concepts of the minimal APIs in .NET 6 with examples.","breadcrumb":{"@id":"https:\/\/code-maze.com\/dotnet-minimal-api\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/dotnet-minimal-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/dotnet-minimal-api\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-aspnetcore.png","width":1100,"height":620,"caption":"ASP.NET Core"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/dotnet-minimal-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"Minimal APIs in .NET 6"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04","name":"Code Maze","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","caption":"Code Maze"},"description":"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.","sameAs":["https:\/\/www.linkedin.com\/company\/codemaze\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/codemazecontributor\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/66646","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=66646"}],"version-history":[{"count":4,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/66646\/revisions"}],"predecessor-version":[{"id":123925,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/66646\/revisions\/123925"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62187"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=66646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=66646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=66646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}