Minimal APIs 6 - Microsoft

Transcription

#DotNet2021ONLINE TECH CONFERENCE22nd June 2021Minimal APIs.NET 6www.dotnet2021.com

Minimal APIsAPIs without controllersThe TeamStephen HalterSenior Software EngineerMaria NaggagaSenior Program ManagerDavid FowlerPartner Software Architect

The Tweet

It’s true thoughLooking around the room

.NET Feels .ComplexGif: Kim's Convenience CBC

.NET Feels .ComplexGif: Kim's Convenience CBCCeremonialGif: Queen Elizabeth II 1953

Challenge AcceptedHello World - Featherhttp

Assembling a crewDid you see twitter ? It started a spicy conversation on howcomplex .NET is in comparison to other frameworks .I have been telling you all for ages .Want to change it ?I am in! We should get Charles to run the user studyand customer development. He’s work is EPIC!

GoalsMinimal APIs Reduce complexity for new people

GoalsMinimal APIs Reduce complexity for new people Reduce ceremony for the all developers

GoalsMinimal APIs Reduce complexity for new people Reduce ceremony for the all developers Embrace minimalism Taking the lessons from .NET Interactive

GoalsMinimal APIs Reduce complexity for new people Reduce ceremony for the all developers Embrace minimalism Taking the lessons from .NET Interactive We grow with you Optimizing for a happy path

Conversations with new peopleOutside our comfort zone

User StudyFormatInterviewed 16 non-.NET developers and invited the complete atutorial.Format.NET Perceptions beforeTutorial.NET Perceptions after

User StudyPerceptions Before“When I think of .NET I think of early 2000 late 1990s era of web developer” Fullstack JavaScript Dev at a mid size company“I don't have a great perception. It's mostly enterprise and I have tried to stayaway from that having coming from a military background.” CTO at Startup Python Dev“I have worked mostly in Startups it isn't widely adopted” GO Developer at a Startup

User StudyTutorialGoal: Build the backend to TodoReact App using .NET

User StudyPerceptions After“It's totally different. I feel like C# has similar syntax to JavaScript so it feels like home” Fullstack JavaScript Dev at a mid size company“ My opinion of .NET might have been unfair It comes down to how many Python I can hire vs .NET. it’s about public perception.” CTO at Startup Python Dev“When I think of .NET I think of something that is difficult to use. From this itdoesn't seem that hard even though I am scratching the surface.” GO Developer at a Startup

Allow me to reintroduce myselfJay Z – PSA 2008

Demo: Minimal ASP.NET Core

DetailsWhere we are going High Performance

DetailsWhere we are going High Performance New C# Features : Improved Lambdas, Global Usings, Top Level Statements New primitives in ASP.NET Core Basic model binding Open APIs Shared Foundation : Use MVC features you love minus the need for acontroller.

.NET APIsController based APIsClassesMethods

.NET APIsAfter without ", [Authorize] (TodoDbContext db) db.Todos.ToListAsync());

.NET APIsNew primitives: Hosting modelpublic class WebApplicationBuilder{IWebHostEnvironment Environment { get; }IServiceCollection Services { get; }Configuration Configuration { get; }ILoggerBuilder Logging { get; }IHostBuilder WebHost { get; }IHostBuilder Host { get; }}public class WebApplication : IHost, IApplicationBuilder, IEndpointRouteBuilder{WebApplication Create(string[] args);WebApplicationBuilder CreateBuilder(string[] args);.}

.NET APIsNew primitivespublic interface IResult{Task ExecuteResultAsync(HttpContext context);}

.NET APIsNew primitivespublic static class RequestDelegateFactory{RequestDelegate Create(Delegate action);}

.NET APIsNew primitives// New streamlined hosting modelvar app WebApplication.Create(args);// New natural typed lambdasvar handler async (int id) : IResult {// Use result types from MVCreturn new JsonResult(.);};// Sprinkle magic sauce on itvar requestDelegate RequestDelegateFactory.Create(handler);// Run as middlewareapp.Run(requestDelegate);

A nodTo the community NancyFx Carter ServiceStack API Endpoints

To learn more about minimal APIs

@ladynaggaga

.NET Perceptions before Tutorial .NET Perceptions after . User Study Perceptions . New primitives in ASP.NET Core Basic model binding Open APIs Shared Foundation : Use MVC features you love minus the need for a controller. Details Where we are going.NET APIs Controller based APIs