WEBVTT

00:00.000 --> 00:05.940
Okay, it's time to start getting our hands dirty, and we're going to be using the dotnet SDK to create

00:05.940 --> 00:07.140
our dotnet projects.

00:07.170 --> 00:11.940
Now you should have had this installed, or you should have installed this as part of the developer

00:11.940 --> 00:12.390
setup.

00:12.390 --> 00:18.030
And just to confirm that we do have this installed and available, we can type into the command line

00:18.030 --> 00:19.950
dotnet info.

00:19.980 --> 00:26.790
And this will give us the information about what dotnet SDK is and the runtimes we have installed.

00:26.820 --> 00:30.720
Now at the time of recording then dotnet nine has just been released.

00:31.410 --> 00:34.710
So I'm using dotnet nine and I can see that I have the.

00:34.890 --> 00:37.440
Net nine runtime installed that I'm highlighting.

00:37.440 --> 00:44.310
And also we have the dotnet SDK installed in my case version 9.0. 100.

00:44.340 --> 00:46.680
Now you don't need to use exactly the same as me.

00:46.680 --> 00:54.450
All I ask is that you use the latest stable released version of DotNet that is available as you're watching

00:54.450 --> 00:54.960
this course.

00:54.960 --> 00:56.520
Now let's possibly.

00:56.670 --> 01:03.080
Net nine if you're watching it when dotnet ten has been released, then please go ahead and installed

01:03.230 --> 01:03.620
net ten.

01:03.620 --> 01:11.300
But please do make sure that it's a released version and not a pre-released version to guarantee maximum

01:11.330 --> 01:13.730
opportunity for success.

01:13.760 --> 01:19.550
So now that we've confirmed that we have Net installed, let's take a look at what we can do with the.

01:19.730 --> 01:21.020
Net SDK.

01:21.050 --> 01:23.660
Now we're going to use it to create a project and a.

01:23.810 --> 01:27.290
Net SDK comes with a number of templates to help us get started.

01:27.440 --> 01:28.490
And if we type in.

01:28.700 --> 01:33.620
Net new list, then we can see a list of the different templates that are available that come with the

01:33.620 --> 01:34.160
SDK.

01:34.190 --> 01:36.020
Now we're going to be creating.

01:36.680 --> 01:41.840
Now we're going to be creating a web API type of project this one here.

01:41.840 --> 01:45.950
So in order to use this then we say dotnet new web API.

01:45.980 --> 01:49.340
We'll also use another few things from inside here as well.

01:49.340 --> 01:57.050
As we create our projects we're going to need a solution file for instance because this is a container

01:57.050 --> 01:59.930
that contains dotnet projects one or more.

01:59.930 --> 02:01.910
Now in our project we're only going to have a single.

02:02.120 --> 02:07.470
Net project, but we'll still create a solution file for it, because that helps us manage our project

02:07.470 --> 02:10.830
inside Visual Studio Code that we'll use very soon.

02:10.860 --> 02:15.570
So let's go about the business of creating what we need inside here.

02:15.570 --> 02:17.100
And I'll just clear my window.

02:17.100 --> 02:21.000
And by the way, I'm operating inside an empty user folder just called demo.

02:21.030 --> 02:25.140
If I list the contents here, then I can see it's empty on windows.

02:25.140 --> 02:30.450
Of course, you would use dir to list the contents of the folder that you're inside of.

02:30.480 --> 02:32.220
Please do use a user folder.

02:32.220 --> 02:38.460
Please do not use a system folder like system32 if you're on windows, and this will ensure that your

02:38.460 --> 02:43.800
project has the correct permissions that you need to do this with.

02:43.830 --> 02:48.270
So let's first of all create a folder that's going to contain our code.

02:48.270 --> 02:52.470
So I'm just going to use mkdir same command on Windows as Mac.

02:52.470 --> 02:54.930
And I'm just going to call this project Restore.

02:55.080 --> 02:59.790
It's a e-commerce store that's based on react I guess.

02:59.790 --> 03:02.580
So that's the name I'm going for.

03:02.760 --> 03:09.080
And I'm just going to CD into this new folder And I'm using the clear command because that clears my

03:09.080 --> 03:09.950
window, obviously.

03:09.980 --> 03:13.250
On windows, if you're in a command prompt it's going to be slightly different.

03:13.250 --> 03:15.140
That would be CLS.

03:15.410 --> 03:18.680
Now we want to create, first of all a new solution file.

03:18.680 --> 03:19.430
And we can use.

03:19.580 --> 03:22.460
Net new SLN to achieve that.

03:22.490 --> 03:27.500
And this will take the name of the folder and give that the name of the solution file.

03:27.500 --> 03:30.590
So I'll press return and that gets created successfully.

03:30.590 --> 03:35.570
And if I take a look then I can see that I now have a restore dot solution file.

03:36.050 --> 03:39.290
What we also need is a web API type of project.

03:39.290 --> 03:41.090
So I'm going to once again say dotnet new.

03:41.120 --> 03:43.010
This time I'm going to say web API.

03:43.220 --> 03:49.340
And I'm going to just get the help for this because there is a switch that we need to add since dotnet

03:49.370 --> 03:52.010
eight, I believe this was enforced.

03:52.370 --> 03:54.620
So I'm just going to get the context help for this.

03:54.620 --> 03:58.670
And inside here we've got a switch that we have to use.

03:58.700 --> 04:05.630
And it tells us or the description of this is whether to use controllers instead of minimal APIs.

04:05.660 --> 04:07.100
Now this is a training course.

04:07.100 --> 04:12.710
Minimum APIs can be useful because they reduce the boilerplate a little bit inside the code.

04:12.950 --> 04:18.620
But for clarity, we want controllers, the full controllers, so that we can see clearly what's going

04:18.620 --> 04:21.920
on rather than reduce the amount of code to its bare minimum.

04:21.920 --> 04:26.810
So we're going to use the controllers switch when we create our new project.

04:26.810 --> 04:31.190
So I'll clear the window once again and I'm going to say dotnet new web API.

04:31.580 --> 04:33.260
And we give it a name.

04:33.260 --> 04:34.910
So I'm going to say dash n.

04:34.910 --> 04:37.070
And I'm just going to call it API.

04:37.190 --> 04:40.790
And I'm going to add the controllers switch.

04:41.300 --> 04:43.820
Now this is going to go ahead and create that project.

04:43.820 --> 04:47.240
And please do ensure you add this controller switch.

04:47.240 --> 04:51.950
If you get this wrong or you miss it, you'll create a project template that's slightly different to

04:51.980 --> 04:54.740
mine and you won't have a controllers folder.

04:54.740 --> 04:57.620
So please do ensure that you have that available.

04:57.650 --> 05:01.460
I'll press return and this is going to go ahead and create that.

05:02.090 --> 05:04.790
And boom it has been created.

05:04.790 --> 05:09.920
And one more thing to do before we proceed is we need to add our new project to the solution file.

05:09.950 --> 05:13.250
So the way that we do that is we can use a solution based command.

05:13.280 --> 05:14.900
So dotnet sln.

05:14.960 --> 05:16.250
Then we can say add.

05:16.250 --> 05:20.000
And we're going to add in by specifying API.

05:20.000 --> 05:21.380
And then just press tab.

05:21.380 --> 05:26.840
And this will go ahead and add our API project to our solution container.

05:26.840 --> 05:28.820
So we're just going to do one quick test.

05:28.820 --> 05:32.210
We're going to open up our project inside Visual Studio Code.

05:32.210 --> 05:37.400
And one way that we can do that is by typing in code followed by a space, followed by a period, and

05:37.400 --> 05:38.660
then pressing return.

05:39.200 --> 05:42.590
And then this should go ahead and open up vs code.

05:43.010 --> 05:45.350
And it's done that in another window.

05:45.350 --> 05:50.960
So I'll just move this across inside here and we can see that we've got our folder, the restore folder

05:50.960 --> 05:57.320
and the API and the files that are part of this new project that we have created.

05:57.530 --> 06:03.770
Now just one thing to check before we move forward is and please ignore any pop ups you get for now,

06:03.950 --> 06:08.210
one thing I'm going to do before I move forward is just make sure the project actually runs.

06:08.210 --> 06:16.730
So inside VS code we do get an integrated terminal On my particular settings, I just press Ctrl and

06:16.760 --> 06:18.170
Apostrophe to open this.

06:18.170 --> 06:25.460
But if that's not the shortcut for yourself, please go to code and then Settings and Keyboard Shortcuts

06:25.460 --> 06:29.060
and just search inside settings for terminal.

06:29.570 --> 06:34.700
As you might want to change this or use something that's convenient because we do use this a lot.

06:34.700 --> 06:37.640
And I'm going to search for toggle terminal.

06:37.670 --> 06:39.440
Toggle is what I'm looking for here.

06:39.440 --> 06:40.670
And it's this one here.

06:40.670 --> 06:45.020
So this is my shortcut key which looks like it's been updated at some point because it's got a user

06:45.020 --> 06:45.230
one.

06:45.230 --> 06:50.450
But please use whatever it is for your version of VSCode just so that you can get to the terminal.

06:50.450 --> 06:54.020
So inside the terminal we're just going to CD into the API folder.

06:54.020 --> 06:57.680
We need to be inside that folder to run this specific project.

06:57.710 --> 07:00.710
And then we can execute dotnet run press return.

07:00.710 --> 07:03.590
And this will start our project running.

07:03.590 --> 07:05.180
Or at least I hope that's what it's going to do.

07:05.180 --> 07:07.070
And finally it has done.

07:07.070 --> 07:08.570
I've just installed dotnet nine.

07:08.570 --> 07:12.590
So maybe the first time you use it it's a little bit slower than normal.

07:12.590 --> 07:17.060
But we can see that our application is running on localhost 5164.

07:17.060 --> 07:22.940
And just as another quick test, let's just see what is or see what we see when we browse to this URL.

07:22.940 --> 07:25.040
So I'm just going to paste that into Chrome.

07:25.040 --> 07:26.660
And it looks like we get nothing.

07:26.690 --> 07:31.490
But that's not strictly true because inside this template please ignore any warnings you see for now

07:31.490 --> 07:32.360
as well.

07:32.420 --> 07:37.940
Inside this template we do have something called a weather forecast controller, and I'll explain about

07:37.940 --> 07:42.890
how the routes work and everything like that as we go along, but we're going to see if we can return

07:42.890 --> 07:45.080
something from this controller.

07:45.110 --> 07:51.230
The code in here basically returns a list of weather forecast summaries, and it's just some demo code

07:51.230 --> 07:52.580
that's provided with the template.

07:52.580 --> 07:57.950
But in order to get to this, we need to specify that we want to go to localhost whatever that port

07:57.950 --> 07:58.220
is.

07:58.250 --> 07:59.750
That's a randomly generated number.

07:59.750 --> 08:04.190
So it would be different for yourself followed by weather forecast to get to the controller.

08:04.220 --> 08:10.520
And if I press return we can see the summary that it returns from our controller endpoint there.

08:10.520 --> 08:16.250
So if we've got to this stage we know that our API functionality is working and we could move on to

08:16.280 --> 08:17.480
the next lesson.
