ASP.NET Core - Minimal Web API In UNDER 5 Minutes!
May 26, 2023
• 3,018 views
asp.net core minimal apiasp.net core minimal web apiasp.net core web api tutorialasp.net core beginner tutorialasp.net core beginnersasp.net core for absolute beginnersminimal apiasp.net minimal apiminimal api c#minimal apis .net 6.net minimal apisdependency injectionvisual studio 2022minimal api dotnet 6.net 6 minimal apiminimal apisc# minimal apiminimal api jwtdotnet 6 minimal apiminimal api dotnet 7minimal apis in .net 6C#dotnet
We're all about efficiency these days, right?! Well, this video demonstrates how INCREDIBLY EASY it is to get started with a web server using ASP.NET Core and the new minimal APIs that are available to us. A perfect spot for beginners to jump in!
For more videos on programming with detailed examples, check this out:
https://www.youtube.com/playlist?list=PLzATctVhnsghN6XlmOvRzwh4JSpkRkj2T
Check out more Dev Leader content (including full in-depth articles with source code examples) here:
https:...
View Transcript
all right in less than five minutes I'm gonna walk us through making a minimal web API in asp.net core and to prove a point I'm going to try to do minimal editing aside from switching from this view to over to visual studio and that way I can try to make my point that you don't need much time at all and you'll understand all the basics to get going with web apis so let's jump right into it alright so I have Visual Studio 2022 pulled up here I have Enterprise Edition but you can do this with Community Edition as well I'm just going to go create a new project and I'm going to select an asp.net core web API and that's in the list over here on the right in this example we're not going to be making a Razer web page for the front end
it's just going to be a web API so make sure to pick this one and we'll press next we'll give it a name I'm just going to leave it as default and put it in where all my Dumping Ground for projects go this next screen you have some options I'm going to explain what I'm picking but if you want to change this up for your purposes you're welcome to do so I am going to have https on I'm not selecting any authentication type I prefer to use Docker so I'm going to have this selected I'm just going to use Linux as the default here we're going to use minimal apis so I do want to have this box unchecked because it says use controllers and then uncheck to use minimal apis so that's what we're doing and then enable open API support I want to
show this just because I'm going to remove some code and actually I want to talk about open API support in a later video so I might link that right after this one and then we're going to use top level statements so keep this one unchecked we'll press create and I will make this a little bit easier for everyone to see but we will jump over to the program.cs file and I'm already about two minutes in so let's go through what we got we have the Builder up at the top to actually take in command line arguments and create a builder that we can start configuring for our web app and actually just to show you all of the extra stuff that's going on here we're going to remove it after and I still think I can do this within time so we can see that
we're actually adding the stuff for the web API documentation that's this Swagger stuff that you see here and as well you can see that right here so we're going to end up removing this and I do want to use https so I'll leave this line here and actually the rest of what you see here aside from this app.run everything else that we have on screen is legitimately just to be able to have an example API for getting weather forecasts so if I go run this right now we do get this API page from Swagger that has the documentation we can press try it out execute it and actually get some responses which is pretty cool so literally within a couple of minutes we have a functioning API and let's go back to the code and actually see all of the pieces that we can remove
just to simplify what you need to have the very Basics so I'm going to remove all the Swagger stuff and we're going to get rid of this API so we don't need that and I actually don't need these other pieces on the minimal API that we have and we can go ahead and remove the body of this and we can say our test API and the cool part is that you can return anything you want in here that can be serialized to Json so we can go make a new object and this will be like an anonymous object right so I can go say name equals Nick and if we go run this now if we hit this route we can actually see that we get back this object that has the name and Nick because it was serialized to Json and that's it in
less than five minutes you only need a couple of lines of code to be able to go create your own web API I did want to include some of the extra stuff so you can see it Stripped Away and only the basics remain and in a future video which I'll link right up here will have another example where we're actually using this API documentation
Frequently Asked Questions
What version of Visual Studio do I need to create a minimal web API?
You can use either Visual Studio 2022 Enterprise Edition or the Community Edition to create a minimal web API.
Do I need to select any authentication type when creating the web API?
No, in this example, I didn't select any authentication type. You can choose to add authentication later if needed.
How can I test the API once it's created?
These FAQs were generated by AI from the video transcript.You can run the API and use the Swagger documentation page that appears to test it out. Just press 'Try it out' and execute to see the responses.
