From the course: Building Web APIs with ASP.NET Core 8

"Hello World" with Visual Studio Code

- Now we will be using Visual Studio to create web APIs. So we do file, where is file new project? There is no file new project. Basically you can open a folder. So in order to create our web API application, we have to do something else. I'll close Visual Studio again and then I head over to my terminal and we can dotnet new and then Web API because that's the project template that we will be using. And if you do dash dash help, then we will get a list of all of the options that we have when calling dotnet new web API, we can provide a name and an output folder. And then we have some options and some of them sound suspiciously similar to what we've seen in Visual Studio. So authentication was here. And then further down below we have stuff whether we would like to use HTTPS or not. So by default we do, but we can set this to off. Basically we can set the framework version of choice. We can disable open API, but we won't. And then we have the dash dash use controllers switch. And by default that's off as you saw in Visual Studio. And now we just dotnet new web API. The output folder is the name of the project. So how about my second ASP Net Core web API? And I'd like to use controllers and that sets up the same kind of project. So if I go to my second ASP Net Core Web API and I just open Visual Studio Code in that folder. And if I trust that template, I get something that looks exactly like the code we've seen before in Visual Studio. And with that out the way, I can go to the run menu and then either start debugging or run without debugging. Depending on whether and how you have been using Visual Studio Code before, you may be prompted to install some extensions that can be helpful. For instance, when working with C# and usually those extensions recommended by Visual Studio Code, really recommended to be installed. So I already did that on the system so I can just do run without debugging. And then same thing happens, so the project is built. And again, that depends on what's installed here. I have to say, okay, what kind of application is this? Is this a Java application? Do I want to do Java debugging or .NET MAUI? No, it's just C#. And then I can pick the configuration I'd like to use when setting up the project. I get an HTTP and an HTTPS configuration and I'd like to use the HTTPS one. And there was the same option in Visual Studio before and HTTPS was the one selected by default. So now we are using basically the same thing. The project is built, we have a terminal here that basically shows us what's happening, shows us the dotnet build call. So that dotnet CLI that we have just been using has also been used in order to compile the project. And then after all has been said and done, once again the web browser will open. And then in the web browser we see the UI we already know. Here it is, you see the project name. And once again, we have that UI to try out what we have built or well, what the dotnet command line interface built for us. So this is still working and this is how you set up a web API project with the CLI so that you can use it within Visual Studio Code.

Contents