Okay, so when we created a new web API type of project, this is what it gave us.
It gave us this controllers folder.
Please make sure you have this.
If you do not have this at this point, then that means you created a minimal API.
And if you click on your program class, you're going to see something a bit different to what I'm displaying
inside here.
So if you do not have this controllers folder you do not have or you have different code inside the
Program.cs class, then please delete what you currently have and start again.
Literally create a solution file and the API project.
Again, it's the quickest way to get to where you need to be.
In this case, you don't want to mess around with the provided code like things in the program class
at this stage if you don't have to.
So let's take a look at what we have inside our project.
Now.
Every dotnet API project has a program class.
This is the entry point to our application and is an important class in our application.
As part of this lesson, we're also going to simplify things to the bare minimum and anything that we
don't need right now, we're also going to remove as well.
Now this is a net nine version of this project.
And in prior versions of Net they used to provide swagger a way of providing documentation about our
endpoints.
Swagger if you've heard of it.
If you haven't, don't worry about it because it's no longer maintained and Microsoft no longer include
it with the templates that we use when we create a new project.
What they've provided instead is open API, and this is something that you would need to configure to
get the kind of swagger functionality that you had before.
So we're not going to use it in this training course.
My goal isn't to provide everything about everything, but a lot about a lot, and some things we're
not going to cover.
And this open API is not going to be covered on this training course, so I'm simply going to remove
it.
Also inside this program class we have two sections really.
We have services things that we add to our projects that we wish to inject into other classes as and
when we need them.
These are referred to as services inside this class and they will go inside effectively.
Consider this part a container for our services, and we'll add them as we go along.
And we'll be adding many to them.
And then we build our application.
And then we've got this HTTP request pipeline.
And this is often referred to as middleware.
So our API and any API really its job is to receive HTTP requests and return HTTP responses as a request
comes into our API server and it goes through what is referred to as a pipeline.
You can think of it as a pipeline, and anything that we add inside this section effectively is referred
to as middleware.
It's software that can do something with that request as it comes in through the pipeline and as it
goes out of the pipeline.
Back to the client that made the HTTP request.
So any middleware and we'll talk about this more as we use this stuff gets added in this part of the
program class.
Now we can check to see which mode we're running in.
And this mode is development.
It's going to use Map Open API.
Once again we're not using it.
So I'm actually going to remove this code from the program class.
Like I say we're going to get things as simple as we can do.
We're not going to use Https redirection.
We're going to start our application using Https.
And we're just not going to redirect it.
So I'm going to remove that.
And we're not going to touch authorization yet.
We're going to come back to that later.
So in the interests of keeping things simple I'm just going to remove that for the time being as well.
So this is what your program class should look like at the moment.
So when our application starts up, it runs this code.
And then this line the app run.
This is responsible for actually running our application and getting us to list stage that we see in
our terminal after we run our application.
So that's the program class, an important class that you'll see inside any web API project.
I'm just going to run through briefly a few other elements inside here.
Another important thing that we need to look at.
And I'm inside the explorer view.
There's two views that we need to think about in VS code.
This one here is the File Explorer view.
But in the Solution Explorer view we get more dotnet type functionality.
So in the Solution Explorer view if I click on API then this takes me to my API Csproj file.
Now there's a couple of things I want to point out inside here.
Any packages that we add that help us develop our code inside our project.
Get added into the project file.
And one of the things that's included with this template is open API.
I've removed the code from the program class.
I don't need it inside here either, so I'm going to remove it from there.
Now we've got the target framework.
This says dotnet nine for myself.
And we've got a couple of flags here nullable and implicit usings.
I just want to briefly mention nullable, because this is quite important about how we deal with something
that's referred to as nullable reference types and the nullable reference types.
If I just pick on this weather forecast class, then we've got a couple of properties inside here.
We've got a data only type of property, an integer property, and the string property.
Now when we use nullable reference types then a string is a reference type in.
Net, an integer is referred to as a value type, and the difference between the two is that the value
type always has to have a value.
An integer can't be null.
It'll either be zero or another value, but the string traditionally how Net has handled this is strings
could have been null.
But when we've got this nullable flag enabled, then if I say that the string is no longer optional.
And that's what this question mark means here, it means that it can be null.
Then I'm going to get a warning from net, and it tells us that Non-nullable property summary must contain
a non-null value when exiting the constructor.
So what this means it's a kind of good thing that.
Net has added in recent versions of Net.
It prevents us from creating properties that we do not know if they should or should not be null.
So if we tell Net that this can be null, then it's going to warn us if we try to use it.
If we haven't checked for null first whether or not it could be null.
So it's just a helpful flag to have enabled, and we'll talk about it more as we build our application
as we'll need to.
Also, we've got this implicit usings.
This is helpful to remove boilerplate in our code.
When it comes to using statements, which we'll talk about as we come across them.
So this is just our project file, and that's about as small as we can get it for our purposes right
now.
A few other things I'll mention just before we move forward.
We have configuration files for our project.
Our projects can receive configuration from these appsettings.json files or app settings dot JSON file.
Now when we're running in development mode then it can read from app settings development JSON as well
as Appsettings.json.
But the more specific version, as in if we're in development and app settings development has the same
value key value pair as Appsettings.json, then the more specific one is used.
And if we're running in production mode, then this file is ignored.
One small change I want to make in here, I'm going to change it from warning to information, just
so that we get maximum information about what's going on as we're running our project.
particularly useful for SQL type queries, so we can see the full query that's being presented to our
database server.
We've also got a controllers folder.
We're going to have API controllers with API controller endpoints that are going to receive the HTTP
requests and respond to them.
We'll come back to these as we'll be creating some of these a bit later.
Another thing I want to point out is inside this properties folder we've got a launch settings.json.
And inside here this is what when we run dotnet run, this is what it looks for to see what it should
start on.
So we can see that the application URL in my case is localhost 5164.
And it would be slightly different for yourself.
I do actually want to change this.
We don't need two profiles.
We've got an HTTP profile and we've got an Https one.
I'm actually going to remove the HTTP one and get rid of it in its entirety.
So we're just going to be using the Https one.
And we don't want to launch the browser.
It's a web API project, and we're just going to start our project on Https.
And I'm just going to change the port number to what was previously the standard default port for a
dotnet project, and change it to https localhost 5001.
Everything else can stay the same.
Now if we stop and restart our project, we should see that change in place.
And I'm just going to execute, not dotnet run.
This time we're going to use dotnet watch because this comes with a file watcher and some basic hot
reloading functionality which doesn't work particularly well, but we'll use it anyway.
And what we should find is that our project is now started on https localhost 5001.
And if we go across to our browser and we put that URL in, then of course we get the page cannot be
found because nothing is listening on the root address.
But if we go to Have the forecast, then we should find that we still get our weather forecast summaries
and we can see that our connection is secured, so on and so forth.
And if that's working for you, brilliant.
Please move on to the next lesson.
If you did have a security warning about not trusted certificates, then I'm just going to demonstrate
what you need to do right now.
So stop your application.
And inside the terminal you just want to execute dotnet dev dash certs https and dash dash clean and
execute this commands.
And then change clean to trust and then execute that command.
And that should enable your computer to trust the self-signed certificate that comes with dotnet.
So if you did run into issues with trusted certificates then please run that command.
But anyway that's our project.
So just a very brief overview of what's contained inside here.
And now we have this in place.
We can move on to the next lesson and create our first entity.