Okay, so we can test our API endpoints in the browser, which has limited utility because we'll soon
find it frustrating to work with.
And there are better tools out there to test our API.
By the way, I'll mention it now, because you may have seen a file in your project called API dot http,
and this is a way of testing API endpoints.
Now in order to use it in VS code, we would need to add an extension.
I believe in Visual Studio you can just right click and run this file and it will test your endpoints.
But you would need to continuously add new entries into this particular file to use this facility to
test your API.
It works and you might want to use it, but I'm not going to demonstrate it or use it in this course.
So I'm just going to delete it because we're going to be using postman to make the tests and API requests
to our API controller endpoints.
So please do open up postman which you should have installed.
I mentioned installing this in the setup lesson and once you open postman you should see something like
this.
It gets updated quite frequently so it may change slightly, but the principles of what we're looking
at will always pretty much stay the same.
So I'm going to create a new workspace.
I have a number of workspaces from various other projects, and I'll create a clean workspace to work
in.
And I'm just going to use the Create workspace.
Create a blank workspace, click next and give it a name of Restore Course and only me.
I don't need to share this with anyone else.
And I'm going to click create.
And this gives us a workspace that we can use.
So postman works with a concept of collection.
So I'm going to say new and I'm going to say collection a collection of requests.
And give it a name of just test for the time being.
And then I can add an example request and we can give our request a name.
I'm just going to give it a name of weather.
We'll just use this one.
Just an example to test the weather forecast controller.
And we can choose what type of request I'm going to make a Get request.
And then we can specify the URL which is going to be https colon forward slash forward Local host.
Colon 5001.
Forward slash API, not API.
Forward slash weather forecast for list one.
And then I'm going to click send.
And this goes and gets the summary of weather forecasts.
Great.
But we also have in postman I'm just going to demonstrate this very briefly is we've got the options
about how we send up our request.
We can send a query string parameters inside here.
If I had a query string I could start saying test and then value.
And notice the URL gets updated with these and I can remove them just as easily.
We also have authorization.
How do we want to authorize our request.
We'll talk about that later.
Any headers that we wish to add with the request.
Anything we want to send up in the body of the request.
We can do so inside here.
And we've got some scripts so we can do something before the request goes and comes after.
We'll take a look at that if we need to.
And we can also do tests inside here as well.
And also, just one other thing I'll mention before I go any further is the console, so we can get
details about the raw request itself.
If we're troubleshooting, we might want to come inside here.
And then we've got access to the request headers, the response headers, the response body, everything
to do with the request in its raw format.
And we might want to do that.
We will see warnings inside here because dotnet uses a self-signed certificate.
Postman is not able to verify it's self-signed certificates.
So don't worry about seeing this yellow color.
It's a warning and we cannot do anything about it because we cannot tell postman to trust our dotnet
certificate, and it doesn't respect whatever we do with our computer in terms of self-signed certificates.
So don't worry about this warning.
Now I've gone ahead and pre-created a collection to make it faster for us to test our API endpoints
as we create them.
So if you go to the course assets folder, once again there's a postman folder, and there's a postman
collection that we can use to test this.
So if we go to postman and let's see.
And we click on the import button, then we can drop in the postman collection that I have provided.
And I'm just going to drag it in to there.
And then we've got our restore collection with all of the different requests that I've pre-created inside
here.
Now there's a couple of things I'll point out as well, just to make our lives a bit easier.
Inside the collection level called restore, we've got some variables.
These are collection level variables, and it's already set to https localhost 5001 for the value URL.
And if I go to one of these requests, not this one, but get the product list, then instead of localhost
5001, I've just replaced it with this variable in a double curly brackets.
And that means if I do change my URL, I only need to update it in one place here.
And then I can test the API endpoints.
So this first one is going to be a Get request to localhost 5001.
So I'm going to click send.
And what we should find is we get the 200, okay, along with our list of products.
If I go to get a single product, I've got API products two.
And if I click send, then I get product with the ID of two back.
And if I say products with the ID of 22, then what we'd expect to see is a 404 not found.
So I'll click send and we get the correct response back from our API server.
So that's what we should be looking at right now.
And we've got a bunch of requests created for other things that we're going to look at as we get to
it in the training course.
So this will just speed us up as we create the code and want to make sure something is working as expected,
it will come back and use these as and when we need to.
So what we're going to take a look at next though is we're going to take a look at our API controller
again.
And what we're doing here is synchronous code to go to our database.
But there is a different option.
And I want to discuss and change this to be asynchronous for when we're making queries to our database.
And I'll explain why next.