SlideShare a Scribd company logo
1 of 33
Coimbatore, India January 21, 2023
Brought to you by
PRESENTS
.Net Conf 2022
Muralidharan Deenathayalan
New features of Minimal APIs in .NET 7
Digital Transformation | Power Platform | SharePoint | Machine
Learning
Brought to you by
Muralidharan Deenathayalan
LinkedIn : https://www.linkedin.com/in/muralidharand/
Twitter : https://twitter.com/muralidharand
GitHub : https://github.com/muralidharand
Blog : www.codingfreaks.net
Brought to you by
Agenda
 API Introduction
 Getting started with Minimal API
 ASP .NET API vs Minimal API
 Advantages of Minimal API
 Disadvantages of Minimal API
 New features of Minimal API in .NET 7
 Demo
 Q & A
Brought to you by
API Introduction
 Communication between two applications
Brought to you by
API Introduction
Database Web Server API Internet Web App 2
Web App 3
Web App 1
Brought to you by
Getting started with Minimal API
 Simplified approach
 Faster APIs
 Minimal code and configurations
 No traditional scaffolding is required
 No controllers and actions overhead
 Minimal != simple
Brought to you by
Getting started with Minimal API
var app = WebApplication.Create(args);
app.MapGet("/", () => "Hello World!");
app.Run();
Brought to you by
Getting started with Minimal API
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/users/{userId}/books/{bookId}", (int userId, int
bookId) => $"The user id is {userId} and book id is {bookId}");
app.Run();
Brought to you by
ASP .NET API vs Minimal API
Minimal API ASP.NET API
Single file based approach Class files are separated in Models, Controllers
and Views
Granular control on your API MVC takes more control
Minimum components are required to build API Relies on Controller, Model and Views
Better performance Good performance
Easy to learn by new developers Need to understand the basics like Models,
Controllers and Views.
PROS
Brought to you by
ASP .NET API vs Minimal API
Minimal API ASP.NET API
Leads to poorly managed code in a single file Controller, Model are exist in different files
Need to implement validation explicitly Model validation supported by default
Structure is not matured, evolving Matured structed
Preferred to build Lightweight API Preferred to build complex APIs
New features are added slowly Great features of out-of-box
CONS
Brought to you by
Advantages of Minimal API
 Easy to get started
 Easy and build faster, POC
 Ideal for building Microservices API
 Granular control
 Can be easily adopted by new developers
 Less code makes faster compile time
Brought to you by
Disadvantages of Minimal API
 Implement custom model validation
 Adding more code lead increases complexity
 Not all features are supported comparatively ASP.NET MVC API
 Can be easily adopted by new developers
 Less code makes faster compile time
Brought to you by
New features of Minimal API in .NET 7
 Endpoint Filters
 Route groups
 Authentication Improvements
 Endpoint metadata providers
 Unit Testing
Brought to you by
Endpoint Filters
 Business logics can be implemented before the actual code executes
 Modify the input params during endpoint filter processing
 Logging the input param details
 Modify the response before returning
 IEndpointFilter – Interface needs to implemented, like IActionFilter
 BeforeEndpoint Execution
 Short-circuit Execution
 AfterEndpoint Execution
Brought to you by
Endpoint Filters
namespace Microsoft.AspNetCore.Http;
public interface IEndpointFilter
{
ValueTask<object?> InvokeAsync(
EndpointFilterInvocationContext context,
EndpointFilterDelegate next);
}
app.MapGet("/student/{name?}", (string? name) =>
new MyResult(name ?? "Hi!"))
.AddEndpointFilter<FILTER_CLASS_NAME>();
Attach your Endpoint filter here
Brought to you by
BeforeEndpoint Execution Filter
public class BeforeEndpointExecution : IEndpointFilter
{
public async ValueTask<object?> InvokeAsync(
EndpointFilterInvocationContext context, EndpointFilterDelegate next)
{
if (context.HttpContext.GetRouteValue("name") is string name)
{
return Results.Ok($"Hi {name}, this is from the filter!");
}
return await next(context);
}
}
app.MapGet("/student/{name?}", (string? name) => new MyResult(name ??
"Hi!"))
.AddEndpointFilter<BeforeEndpointExecution>();
Brought to you by
Short-Circuit Execution Filter
public class ShortCircuit : IEndpointFilter
{
public ValueTask<object?> InvokeAsync(
EndpointFilterInvocationContext context,
EndpointFilterDelegate next)
{
return new ValueTask<object?>(Results.Json(new { Name = "hello" }));
}
}
app.MapGet("/student/{name?}", (string? name) => new MyResult(name ??
"Hi!"))
.AddEndpointFilter<ShortCircuit>();
Brought to you by
AfterEndpoint Execution Filter
app.MapGet("/student/{name?}", (string? name) =>
new MyResult(name ?? "Hi!"))
.AddEndpointFilter<AfterEndpointExecution>();
public class AfterEndpointExecution : IEndpointFilter
{
public async ValueTask<object?> InvokeAsync(
EndpointFilterInvocationContext context,EndpointFilterDelegate next){
var result = await next(context);
if (result is MyResultWithEndpoint dp &&
context.HttpContext.GetEndpoint() is { } e)
{ dp.EndpointDisplayName = e.DisplayName ?? "";}
return result;
}
}
Brought to you by
Endpoint Filters
 BeforeEndpoint filter will be executed in FIFO (First In, First Out)
 AfterEndpoint filter will be executed in FILO (First In, Last Out)
Points to be remembered
Brought to you by
Route groups
 MapGroups – Extension method for grouping common endpoints.
 Applying RequireAuthentication() or any other endpoint filter will be
applied all group member methods.
MapGroups can be nested.
Brought to you by
Route groups
app.MapGroup("/public/todos")
.MapTodosApi();
public static RouteGroupBuilder MapTodosApi
(this RouteGroupBuilder group)
{
group.MapGet("/", () => "Hello route");
group.MapGet("/{id}", () => "Hello route");
group.MapPost("/", () => "Hello route");
group.MapPut("/{id}", () => "Hello route");
group.MapDelete("/{id}", () => "Hello route");
return group;
}
Brought to you by
Route groups
app.MapGroup("/public/todos")
.MapTodosApi().RequireAuthorization();
public static RouteGroupBuilder MapTodosApi
(this RouteGroupBuilder group)
{
group.MapGet("/", () => "Hello route");
group.MapGet("/{id}", () => "Hello route");
group.MapPost("/", () => "Hello route");
group.MapPut("/{id}", () => "Hello route");
group.MapDelete("/{id}", () => "Hello route");
return group;
}
Brought to you by
Authentication Improvements
 Default Authentication Scheme
 Simplified Authentication Configuration
 Authorization Policies for Specific Endpoints
 New user-jwts tool
Brought to you by
Default Authentication Scheme
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationS
cheme)
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options
=>
{
//actual code goes here
});
builder.Services.AddAuthentication() //👈 no default scheme
specified
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options
=>
{
//actual code goes here
});
.NET 6
.NET 7
Brought to you by
Simplified Authentication Configuration
.NET 6
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options
=>
{
options.Authority =
$"https://{builder.Configuration["My:Domain"]}";
options.TokenValidationParameters =
new Microsoft.IdentityModel.Tokens.TokenValidationParameters
{
ValidAudience = builder.Configuration["My:Audience"],
ValidIssuer = $"{builder.Configuration["My:Domain"]}"
};
});
Brought to you by
Simplified Authentication Configuration
.NET 7
builder.Services.AddAuthentication().AddJwtBearer(); //👈 new feature
appsetting.json
{
"AllowedHosts": "*",
"Authentication": {
"Schemes": {
"Bearer": {
"Authority": "https://YOUR_AUTH0_DOMAIN",
"ValidAudiences": [ "YOUR_AUDIENCE" ],
"ValidIssuer": "YOUR_AUTH0_DOMAIN"
}
}
}
}
Brought to you by
Simplified Authentication Configuration
.NET 7
builder.Services.AddAuthentication().AddJwtBearer(); //👈 new feature
appsetting.json
{
"AllowedHosts": "*",
"Authentication": {
"DefaultScheme" : "JwtBearer",
"Schemes": {
"JwtBearer": {
"Audiences": [ "http://localhost:5000", "https://localhost:5001" ],
"ClaimsIssuer": "dotnet-user-jwts"
}
}
}
}
Brought to you by
Authorization Policies for Specific
Endpoints
app.MapGet("/api/hello", () => "Hello!")
.RequireAuthorization(p => p.RequireClaim("scope",
"api:admin"));
Brought to you by
user-jwts tool
dotnet user-jwts create
Brought to you by
user-jwts tool
https://jwt.ms/
Brought to you by
Demo
Brought to you by
Muralidharan Deenathayalan
LinkedIn : https://www.linkedin.com/in/muralidharand/
Twitter : https://twitter.com/muralidharand
GitHub : https://github.com/muralidharand
Blog : www.codingfreaks.net
Brought to you by
Thank You!

More Related Content

What's hot

Integrating Splunk into your Spring Applications
Integrating Splunk into your Spring ApplicationsIntegrating Splunk into your Spring Applications
Integrating Splunk into your Spring ApplicationsDamien Dallimore
 
Kubernetes - Security Journey
Kubernetes - Security JourneyKubernetes - Security Journey
Kubernetes - Security JourneyJerry Jalava
 
Microservice Architecture
Microservice ArchitectureMicroservice Architecture
Microservice ArchitectureNguyen Tung
 
The Kubernetes Gateway API and its role in Cloud Native API Management
The Kubernetes Gateway API and its role in Cloud Native API ManagementThe Kubernetes Gateway API and its role in Cloud Native API Management
The Kubernetes Gateway API and its role in Cloud Native API ManagementNuwan Dias
 
Introduction to Kubernetes and Google Container Engine (GKE)
Introduction to Kubernetes and Google Container Engine (GKE)Introduction to Kubernetes and Google Container Engine (GKE)
Introduction to Kubernetes and Google Container Engine (GKE)Opsta
 
introduction to Vue.js 3
introduction to Vue.js 3 introduction to Vue.js 3
introduction to Vue.js 3 ArezooKmn
 
Kubernetes Introduction
Kubernetes IntroductionKubernetes Introduction
Kubernetes IntroductionEric Gustafson
 
Quarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java frameworkQuarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java frameworkSVDevOps
 
Learn Terraform on Azure
Learn Terraform on AzureLearn Terraform on Azure
Learn Terraform on AzureJorn Jambers
 
Flutter 踩雷心得
Flutter 踩雷心得Flutter 踩雷心得
Flutter 踩雷心得Weizhong Yang
 
CI/CD trên Cloud OpenStack tại Viettel Networks | Hà Minh Công, Phạm Tường Chiến
CI/CD trên Cloud OpenStack tại Viettel Networks | Hà Minh Công, Phạm Tường ChiếnCI/CD trên Cloud OpenStack tại Viettel Networks | Hà Minh Công, Phạm Tường Chiến
CI/CD trên Cloud OpenStack tại Viettel Networks | Hà Minh Công, Phạm Tường ChiếnVietnam Open Infrastructure User Group
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignRyan Riley
 

What's hot (20)

Integrating Splunk into your Spring Applications
Integrating Splunk into your Spring ApplicationsIntegrating Splunk into your Spring Applications
Integrating Splunk into your Spring Applications
 
Kubernetes - Security Journey
Kubernetes - Security JourneyKubernetes - Security Journey
Kubernetes - Security Journey
 
Microservice Architecture
Microservice ArchitectureMicroservice Architecture
Microservice Architecture
 
The Kubernetes Gateway API and its role in Cloud Native API Management
The Kubernetes Gateway API and its role in Cloud Native API ManagementThe Kubernetes Gateway API and its role in Cloud Native API Management
The Kubernetes Gateway API and its role in Cloud Native API Management
 
Introduction to Kubernetes and Google Container Engine (GKE)
Introduction to Kubernetes and Google Container Engine (GKE)Introduction to Kubernetes and Google Container Engine (GKE)
Introduction to Kubernetes and Google Container Engine (GKE)
 
introduction to Vue.js 3
introduction to Vue.js 3 introduction to Vue.js 3
introduction to Vue.js 3
 
Kubernetes 101
Kubernetes 101Kubernetes 101
Kubernetes 101
 
Gitlab CI/CD
Gitlab CI/CDGitlab CI/CD
Gitlab CI/CD
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Event Storming and Saga
Event Storming and SagaEvent Storming and Saga
Event Storming and Saga
 
Kubernetes Introduction
Kubernetes IntroductionKubernetes Introduction
Kubernetes Introduction
 
Architecture: Microservices
Architecture: MicroservicesArchitecture: Microservices
Architecture: Microservices
 
Quarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java frameworkQuarkus - a next-generation Kubernetes Native Java framework
Quarkus - a next-generation Kubernetes Native Java framework
 
Learn Terraform on Azure
Learn Terraform on AzureLearn Terraform on Azure
Learn Terraform on Azure
 
Flutter 踩雷心得
Flutter 踩雷心得Flutter 踩雷心得
Flutter 踩雷心得
 
Micro-frontend
Micro-frontendMicro-frontend
Micro-frontend
 
CI/CD trên Cloud OpenStack tại Viettel Networks | Hà Minh Công, Phạm Tường Chiến
CI/CD trên Cloud OpenStack tại Viettel Networks | Hà Minh Công, Phạm Tường ChiếnCI/CD trên Cloud OpenStack tại Viettel Networks | Hà Minh Công, Phạm Tường Chiến
CI/CD trên Cloud OpenStack tại Viettel Networks | Hà Minh Công, Phạm Tường Chiến
 
Creating Apps with .NET MAUI
Creating Apps with .NET MAUICreating Apps with .NET MAUI
Creating Apps with .NET MAUI
 
Springboot Microservices
Springboot MicroservicesSpringboot Microservices
Springboot Microservices
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 

Similar to New features of Minimal APIs in .NET 7 -Muralidharan Deenathayalan.pptx

Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteorSapna Upreti
 
How to code to code less
How to code to code lessHow to code to code less
How to code to code lessAnton Novikau
 
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...Fwdays
 
ASP.NET Core Web API documentation web application
ASP.NET Core Web API documentation web applicationASP.NET Core Web API documentation web application
ASP.NET Core Web API documentation web applicationAMARAAHMED7
 
Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1
Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1
Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1Rodolfo Finochietti
 
Ruby on Rails vs ASP.NET MVC
Ruby on Rails vs ASP.NET MVCRuby on Rails vs ASP.NET MVC
Ruby on Rails vs ASP.NET MVCSimone Chiaretta
 
Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Matt Raible
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Eliran Eliassy
 
A Minimalist’s Attempt at Building a Distributed Application
A Minimalist’s Attempt at Building a Distributed ApplicationA Minimalist’s Attempt at Building a Distributed Application
A Minimalist’s Attempt at Building a Distributed ApplicationDavid Hoerster
 
Reactive Application Using METEOR
Reactive Application Using METEORReactive Application Using METEOR
Reactive Application Using METEORNodeXperts
 
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)Amazon Web Services
 
Http programming in play
Http programming in playHttp programming in play
Http programming in playKnoldus Inc.
 
Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0Steven Smith
 
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...OdessaJS Conf
 
Spring Cloud Function — Going Serverless
Spring Cloud Function — Going ServerlessSpring Cloud Function — Going Serverless
Spring Cloud Function — Going ServerlessGlobalLogic Ukraine
 
Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Matt Raible
 
Getting Started with Zend Framework
Getting Started with Zend FrameworkGetting Started with Zend Framework
Getting Started with Zend FrameworkJuan Antonio
 

Similar to New features of Minimal APIs in .NET 7 -Muralidharan Deenathayalan.pptx (20)

Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 
How to code to code less
How to code to code lessHow to code to code less
How to code to code less
 
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
 
ASP.NET Core Web API documentation web application
ASP.NET Core Web API documentation web applicationASP.NET Core Web API documentation web application
ASP.NET Core Web API documentation web application
 
Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1
Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1
Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1
 
Ruby on Rails vs ASP.NET MVC
Ruby on Rails vs ASP.NET MVCRuby on Rails vs ASP.NET MVC
Ruby on Rails vs ASP.NET MVC
 
Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017
 
2007 Zend Con Mvc
2007 Zend Con Mvc2007 Zend Con Mvc
2007 Zend Con Mvc
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
 
A Minimalist’s Attempt at Building a Distributed Application
A Minimalist’s Attempt at Building a Distributed ApplicationA Minimalist’s Attempt at Building a Distributed Application
A Minimalist’s Attempt at Building a Distributed Application
 
Reactive Application Using METEOR
Reactive Application Using METEORReactive Application Using METEOR
Reactive Application Using METEOR
 
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
AWS re:Invent 2016: Chalice: A Serverless Microframework for Python (DEV308)
 
Http programming in play
Http programming in playHttp programming in play
Http programming in play
 
Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0Introducing ASP.NET Core 2.0
Introducing ASP.NET Core 2.0
 
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
 
Spring Cloud Function — Going Serverless
Spring Cloud Function — Going ServerlessSpring Cloud Function — Going Serverless
Spring Cloud Function — Going Serverless
 
Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017
 
Getting Started with Zend Framework
Getting Started with Zend FrameworkGetting Started with Zend Framework
Getting Started with Zend Framework
 
2007 Zend Con Mvc Edited Irmantas
2007 Zend Con Mvc Edited Irmantas2007 Zend Con Mvc Edited Irmantas
2007 Zend Con Mvc Edited Irmantas
 
Clean Architecture @ Taxibeat
Clean Architecture @ TaxibeatClean Architecture @ Taxibeat
Clean Architecture @ Taxibeat
 

Recently uploaded

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 

Recently uploaded (20)

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 

New features of Minimal APIs in .NET 7 -Muralidharan Deenathayalan.pptx

  • 1. Coimbatore, India January 21, 2023 Brought to you by PRESENTS .Net Conf 2022 Muralidharan Deenathayalan New features of Minimal APIs in .NET 7 Digital Transformation | Power Platform | SharePoint | Machine Learning
  • 2. Brought to you by Muralidharan Deenathayalan LinkedIn : https://www.linkedin.com/in/muralidharand/ Twitter : https://twitter.com/muralidharand GitHub : https://github.com/muralidharand Blog : www.codingfreaks.net
  • 3. Brought to you by Agenda  API Introduction  Getting started with Minimal API  ASP .NET API vs Minimal API  Advantages of Minimal API  Disadvantages of Minimal API  New features of Minimal API in .NET 7  Demo  Q & A
  • 4. Brought to you by API Introduction  Communication between two applications
  • 5. Brought to you by API Introduction Database Web Server API Internet Web App 2 Web App 3 Web App 1
  • 6. Brought to you by Getting started with Minimal API  Simplified approach  Faster APIs  Minimal code and configurations  No traditional scaffolding is required  No controllers and actions overhead  Minimal != simple
  • 7. Brought to you by Getting started with Minimal API var app = WebApplication.Create(args); app.MapGet("/", () => "Hello World!"); app.Run();
  • 8. Brought to you by Getting started with Minimal API var builder = WebApplication.CreateBuilder(args); var app = builder.Build(); app.MapGet("/users/{userId}/books/{bookId}", (int userId, int bookId) => $"The user id is {userId} and book id is {bookId}"); app.Run();
  • 9. Brought to you by ASP .NET API vs Minimal API Minimal API ASP.NET API Single file based approach Class files are separated in Models, Controllers and Views Granular control on your API MVC takes more control Minimum components are required to build API Relies on Controller, Model and Views Better performance Good performance Easy to learn by new developers Need to understand the basics like Models, Controllers and Views. PROS
  • 10. Brought to you by ASP .NET API vs Minimal API Minimal API ASP.NET API Leads to poorly managed code in a single file Controller, Model are exist in different files Need to implement validation explicitly Model validation supported by default Structure is not matured, evolving Matured structed Preferred to build Lightweight API Preferred to build complex APIs New features are added slowly Great features of out-of-box CONS
  • 11. Brought to you by Advantages of Minimal API  Easy to get started  Easy and build faster, POC  Ideal for building Microservices API  Granular control  Can be easily adopted by new developers  Less code makes faster compile time
  • 12. Brought to you by Disadvantages of Minimal API  Implement custom model validation  Adding more code lead increases complexity  Not all features are supported comparatively ASP.NET MVC API  Can be easily adopted by new developers  Less code makes faster compile time
  • 13. Brought to you by New features of Minimal API in .NET 7  Endpoint Filters  Route groups  Authentication Improvements  Endpoint metadata providers  Unit Testing
  • 14. Brought to you by Endpoint Filters  Business logics can be implemented before the actual code executes  Modify the input params during endpoint filter processing  Logging the input param details  Modify the response before returning  IEndpointFilter – Interface needs to implemented, like IActionFilter  BeforeEndpoint Execution  Short-circuit Execution  AfterEndpoint Execution
  • 15. Brought to you by Endpoint Filters namespace Microsoft.AspNetCore.Http; public interface IEndpointFilter { ValueTask<object?> InvokeAsync( EndpointFilterInvocationContext context, EndpointFilterDelegate next); } app.MapGet("/student/{name?}", (string? name) => new MyResult(name ?? "Hi!")) .AddEndpointFilter<FILTER_CLASS_NAME>(); Attach your Endpoint filter here
  • 16. Brought to you by BeforeEndpoint Execution Filter public class BeforeEndpointExecution : IEndpointFilter { public async ValueTask<object?> InvokeAsync( EndpointFilterInvocationContext context, EndpointFilterDelegate next) { if (context.HttpContext.GetRouteValue("name") is string name) { return Results.Ok($"Hi {name}, this is from the filter!"); } return await next(context); } } app.MapGet("/student/{name?}", (string? name) => new MyResult(name ?? "Hi!")) .AddEndpointFilter<BeforeEndpointExecution>();
  • 17. Brought to you by Short-Circuit Execution Filter public class ShortCircuit : IEndpointFilter { public ValueTask<object?> InvokeAsync( EndpointFilterInvocationContext context, EndpointFilterDelegate next) { return new ValueTask<object?>(Results.Json(new { Name = "hello" })); } } app.MapGet("/student/{name?}", (string? name) => new MyResult(name ?? "Hi!")) .AddEndpointFilter<ShortCircuit>();
  • 18. Brought to you by AfterEndpoint Execution Filter app.MapGet("/student/{name?}", (string? name) => new MyResult(name ?? "Hi!")) .AddEndpointFilter<AfterEndpointExecution>(); public class AfterEndpointExecution : IEndpointFilter { public async ValueTask<object?> InvokeAsync( EndpointFilterInvocationContext context,EndpointFilterDelegate next){ var result = await next(context); if (result is MyResultWithEndpoint dp && context.HttpContext.GetEndpoint() is { } e) { dp.EndpointDisplayName = e.DisplayName ?? "";} return result; } }
  • 19. Brought to you by Endpoint Filters  BeforeEndpoint filter will be executed in FIFO (First In, First Out)  AfterEndpoint filter will be executed in FILO (First In, Last Out) Points to be remembered
  • 20. Brought to you by Route groups  MapGroups – Extension method for grouping common endpoints.  Applying RequireAuthentication() or any other endpoint filter will be applied all group member methods. MapGroups can be nested.
  • 21. Brought to you by Route groups app.MapGroup("/public/todos") .MapTodosApi(); public static RouteGroupBuilder MapTodosApi (this RouteGroupBuilder group) { group.MapGet("/", () => "Hello route"); group.MapGet("/{id}", () => "Hello route"); group.MapPost("/", () => "Hello route"); group.MapPut("/{id}", () => "Hello route"); group.MapDelete("/{id}", () => "Hello route"); return group; }
  • 22. Brought to you by Route groups app.MapGroup("/public/todos") .MapTodosApi().RequireAuthorization(); public static RouteGroupBuilder MapTodosApi (this RouteGroupBuilder group) { group.MapGet("/", () => "Hello route"); group.MapGet("/{id}", () => "Hello route"); group.MapPost("/", () => "Hello route"); group.MapPut("/{id}", () => "Hello route"); group.MapDelete("/{id}", () => "Hello route"); return group; }
  • 23. Brought to you by Authentication Improvements  Default Authentication Scheme  Simplified Authentication Configuration  Authorization Policies for Specific Endpoints  New user-jwts tool
  • 24. Brought to you by Default Authentication Scheme builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationS cheme) .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options => { //actual code goes here }); builder.Services.AddAuthentication() //👈 no default scheme specified .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options => { //actual code goes here }); .NET 6 .NET 7
  • 25. Brought to you by Simplified Authentication Configuration .NET 6 builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options => { options.Authority = $"https://{builder.Configuration["My:Domain"]}"; options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters { ValidAudience = builder.Configuration["My:Audience"], ValidIssuer = $"{builder.Configuration["My:Domain"]}" }; });
  • 26. Brought to you by Simplified Authentication Configuration .NET 7 builder.Services.AddAuthentication().AddJwtBearer(); //👈 new feature appsetting.json { "AllowedHosts": "*", "Authentication": { "Schemes": { "Bearer": { "Authority": "https://YOUR_AUTH0_DOMAIN", "ValidAudiences": [ "YOUR_AUDIENCE" ], "ValidIssuer": "YOUR_AUTH0_DOMAIN" } } } }
  • 27. Brought to you by Simplified Authentication Configuration .NET 7 builder.Services.AddAuthentication().AddJwtBearer(); //👈 new feature appsetting.json { "AllowedHosts": "*", "Authentication": { "DefaultScheme" : "JwtBearer", "Schemes": { "JwtBearer": { "Audiences": [ "http://localhost:5000", "https://localhost:5001" ], "ClaimsIssuer": "dotnet-user-jwts" } } } }
  • 28. Brought to you by Authorization Policies for Specific Endpoints app.MapGet("/api/hello", () => "Hello!") .RequireAuthorization(p => p.RequireClaim("scope", "api:admin"));
  • 29. Brought to you by user-jwts tool dotnet user-jwts create
  • 30. Brought to you by user-jwts tool https://jwt.ms/
  • 31. Brought to you by Demo
  • 32. Brought to you by Muralidharan Deenathayalan LinkedIn : https://www.linkedin.com/in/muralidharand/ Twitter : https://twitter.com/muralidharand GitHub : https://github.com/muralidharand Blog : www.codingfreaks.net
  • 33. Brought to you by Thank You!