WEBVTT

00:03.790 --> 00:05.230
Hey did everyone that they share.

00:05.230 --> 00:08.650
And welcome to another video of the pro back end developer course.

00:08.770 --> 00:13.240
Now our application is looking good and it's fine and we can definitely move forward in building the

00:13.240 --> 00:14.080
application.

00:14.080 --> 00:16.960
But of course the goal is not to build that toy application.

00:16.960 --> 00:20.560
The goal is to understand the in depth of what we're trying to achieve here.

00:20.650 --> 00:25.690
Now, two new keywords are right in front of us, the first one being request and the second one being

00:25.690 --> 00:26.430
response.

00:26.440 --> 00:31.120
In fact, many of the time you are going to see that there is something like a next or there is a whole

00:31.120 --> 00:32.170
lot of things that goes on.

00:32.170 --> 00:36.970
But right now the goal is really simple that I want to understand more in-depth about request and the

00:36.970 --> 00:37.810
response.

00:37.820 --> 00:40.270
Now, the request is something which we have already seen.

00:40.270 --> 00:45.970
This can be a type of get post put and delete and a little bit more, but this is all the requests that

00:45.970 --> 00:48.160
you are trying to make to the server.

00:48.160 --> 00:52.900
And not only just you can take some things like that, you have type to search on, you can take a lot

00:52.900 --> 00:56.230
of information to the server at the time of requesting it.

00:56.260 --> 01:01.930
Similarly, server can respond and server response you in the form of response, also known as this

01:01.930 --> 01:02.560
rest.

01:02.560 --> 01:05.020
And this is how we are sending back this data.

01:05.020 --> 01:07.660
But we need a little bit more in-depth analysis of that.

01:07.660 --> 01:12.700
And this analysis and this study is going to depend on what kind of framework you are choosing on.

01:12.700 --> 01:13.900
We are choosing EXPRESS.

01:13.900 --> 01:16.930
So we're going to study the Express documentation in case you choose something else.

01:16.930 --> 01:21.070
Obviously have to study different, but after this course, okay, let's move on.

01:21.070 --> 01:23.710
So this is the basics and let's go up here.

01:24.010 --> 01:26.380
So first, let's talk about how this is happening.

01:26.380 --> 01:29.320
So Web request in response, we have already gone through that request.

01:29.320 --> 01:35.050
Is there as soon as you make a request on the Web, the Web starts analyzing that request process,

01:35.050 --> 01:40.660
that request, maybe grab some data from the database and then finally it gets you a response back.

01:40.660 --> 01:46.240
But not only just response, it also sometimes gets you a status or also known as status code.

01:46.270 --> 01:47.470
This is really important.

01:47.470 --> 01:54.220
This is the information that is important to write better APIs or as well as formal APIs or the production

01:54.220 --> 01:55.300
grade APIs.

01:55.300 --> 01:59.770
Let's go ahead and obviously I have a link for you to explore on these Web requests.

01:59.770 --> 02:01.450
So let's go ahead and open this up.

02:01.450 --> 02:04.000
So this is the HTTP response status code.

02:04.000 --> 02:05.680
You don't need to memorize any of it.

02:05.680 --> 02:11.680
There are only a handful of few which we use, but if you know a lot more, that is always great.

02:11.680 --> 02:17.890
So for all the information, informational response we use between 100 to 199, I'll explain more in

02:17.890 --> 02:21.940
detail what those are for successful response 202 to 99.

02:21.940 --> 02:26.110
This is usually the range you are going to be mostly using 200 or 201.

02:26.110 --> 02:28.000
Then there is a redirection message.

02:28.000 --> 02:31.840
You won't be using too much of the 300 codes 405 hundred code.

02:31.840 --> 02:36.340
You'll be using 400 code for when a client gives you something wrong.

02:36.340 --> 02:41.470
Information for something like a wrong email or something like this or the password doesn't match.

02:41.470 --> 02:45.400
We use a range of 400 code and then 500 code.

02:45.400 --> 02:49.780
Now the good thing is these codes are not kind of governance bodies.

02:49.780 --> 02:54.940
You can decide that whatever the code you want to return, of course you can return for all successful

02:54.940 --> 02:58.960
message 200 code, but nobody is stopping you to return a 400 code.

02:58.960 --> 03:03.220
Of course it would be bad for the API design, but nobody's stopping you to do so.

03:03.250 --> 03:04.210
I am stopping you.

03:04.210 --> 03:04.960
Please don't do this.

03:04.960 --> 03:05.950
This is really bad.

03:06.360 --> 03:08.140
A couple of ones which I would like to introduce.

03:08.140 --> 03:12.760
You don't need to remember all of them for all the get head put, body trace, all kinds of this you'll

03:12.760 --> 03:13.960
be mostly using 200.

03:13.960 --> 03:15.550
200 means everything is okay.

03:15.550 --> 03:16.870
It was successful.

03:16.900 --> 03:22.060
Now it is recommended that for all the post input request you send at 201, whenever there is a new

03:22.060 --> 03:27.160
record being created in the database, you'll find that majority of the Pro-level organization use this

03:27.160 --> 03:29.350
specific code, so make sure you remember that.

03:29.350 --> 03:34.570
But in the majority of the applications and videos and courses, we actually tend to use 200 more.

03:34.570 --> 03:35.740
And this is all okay.

03:35.740 --> 03:37.420
This is not bad at all.

03:37.420 --> 03:41.110
Now in the 300 you won't be using too much of the redirections of the code.

03:41.110 --> 03:43.630
Something like 300 not found in all of that.

03:43.630 --> 03:47.710
So these are rarely used, but most of the time you'll be using 400.

03:47.710 --> 03:50.740
These are for client requests, like bad request.

03:50.740 --> 03:54.670
Or maybe somebody is trying to access a resource which is not authorized for him.

03:54.670 --> 03:56.410
The payment for or to nobody.

03:56.410 --> 03:59.560
I've seen ever you using this one so I don't know.

03:59.920 --> 04:01.210
It might be used somewhere.

04:01.210 --> 04:07.360
403 is almost similar to 401, but this is forbidden for every one resource and stuff like that.

04:07.360 --> 04:10.390
500 is definitely when something goes wrong onto the server.

04:10.390 --> 04:13.390
So you're going to see scrolling a little bit something like Bad Gateway.

04:13.390 --> 04:18.580
You might have seen this many times and internal server error, of course, a famous one now one of

04:18.580 --> 04:20.290
the common one is 4 to 4.

04:20.290 --> 04:24.490
I'm pretty sure that most of you might be familiar with the 404 not found.

04:24.490 --> 04:28.420
When you don't find the resource on the server again, you don't need to memorize all of them.

04:28.420 --> 04:31.060
Just remember that 200 and 201 are okay.

04:31.060 --> 04:33.520
Responses 404 is not found.

04:33.520 --> 04:37.420
400 is just basically there is something wrong from the client side.

04:37.690 --> 04:39.910
So something like bad request or something.

04:39.910 --> 04:44.620
And 401 is unauthorized 500 is something went wrong from our site on the server.

04:44.620 --> 04:46.900
These are the basic ones that you have to remember.

04:47.320 --> 04:51.190
So this is the basics now coming back onto the express.

04:52.000 --> 04:55.120
Now this time we'll be going a little bit more than the getting started.

04:55.120 --> 04:55.690
This guide.

04:55.690 --> 04:58.630
We need to understand how the APIs of Express works.

04:58.630 --> 05:00.910
Yes, they have their own APIs as well.

05:01.030 --> 05:01.450
So let's.

05:01.500 --> 05:03.870
Go on to the five X because that's what we are using.

05:03.870 --> 05:08.040
And again, in case you want to get more detail which one you should be looking for, you can go ahead

05:08.040 --> 05:08.880
and look for that.

05:08.880 --> 05:10.890
We are using a 4.71.

05:10.890 --> 05:14.340
So of course the version five is not yet being released.

05:14.340 --> 05:17.580
So you might be looking for the four x, not the five x.

05:17.580 --> 05:21.840
So let's go ahead and look for four X in case you want to check out the five x, this is exactly how

05:21.840 --> 05:22.830
you would be doing.

05:22.920 --> 05:26.010
So here we can see we have a request and we have a response.

05:26.010 --> 05:28.590
First, let's see what all we can do in the request.

05:28.590 --> 05:31.530
So you can see there is a whole lot of things that can come up in the request.

05:31.530 --> 05:37.050
You can access the body, you can access the base URL, you can access cookies, you can access host

05:37.050 --> 05:37.530
name.

05:37.530 --> 05:39.150
There's a whole lot that we can do here.

05:39.150 --> 05:40.830
There is a path, there is params.

05:40.830 --> 05:42.690
I will explain them in more detail.

05:42.690 --> 05:45.210
There is a query route, signed cookies.

05:45.210 --> 05:47.370
There's a whole lot that comes up with the request.

05:47.460 --> 05:52.380
And of course, I know many of you didn't realize this, but yes, cookies and parameters and token,

05:52.380 --> 05:58.200
even when you reset your password or you access the email first time and you create an account and say,

05:58.200 --> 06:03.000
hey, I'm authorized, this is all been coming up in the token from the URL itself and this all comes

06:03.000 --> 06:03.870
from the request.

06:03.870 --> 06:04.770
So this is it.

06:04.980 --> 06:09.990
And when it comes to the response, this is where the response comes in or response from the server

06:09.990 --> 06:13.440
side is being sent to anybody who is requesting it.

06:13.440 --> 06:18.810
So you can send headers and this is the most common one and you can also go ahead and use something

06:18.810 --> 06:22.500
like resource send that we just use, which is somewhere here.

06:22.500 --> 06:27.630
There we go, restart, send and this is what we have been using, resort send and we send up some paragraph

06:27.630 --> 06:28.380
or something like that.

06:28.380 --> 06:29.910
So this is where it is coming up.

06:30.000 --> 06:35.610
You can also send raised or JSON and we can send the JSON data which we'll be sending up in a minute

06:35.610 --> 06:36.600
and all of that.

06:37.050 --> 06:39.450
But there is an important one which you are going to see.

06:39.450 --> 06:42.960
There is a red dot send status and resource status.

06:42.960 --> 06:49.500
So I told you status is for raising something like four or three, 400, whatever the status is, but

06:49.500 --> 06:53.490
very similar of that which is red dot send status.

06:53.490 --> 06:57.840
So what's the difference between the resort status and resort send status?

06:58.260 --> 07:01.440
Not too much resident status send status.

07:01.440 --> 07:06.000
Actually, you not only just send the status, you actually bind it up with a little bit more.

07:06.000 --> 07:07.950
Like you can see that as dot status.

07:08.190 --> 07:12.930
When you want to simply say send status, that means I only want to send the status, just the code

07:12.930 --> 07:16.620
400 300 201, whatever.

07:16.620 --> 07:21.840
But when I use something like resident status, then I can just use the status to send the status,

07:21.840 --> 07:27.150
but I can also chain on this dot send to send whatever the request is that I'm sending you.

07:27.150 --> 07:30.240
And again, all you have to do is come up here and read that.

07:30.240 --> 07:35.430
For example, if you want to set some cookies, you have to say it as dot cookie and stuff like that.

07:35.430 --> 07:37.020
So that's all what we do.

07:37.050 --> 07:41.310
Now, let's go ahead and modify our request that we have sent to make it a little bit more professional.

07:41.310 --> 07:42.660
Not too much, but a little bit.

07:42.660 --> 07:48.390
So I can simply say resident status and this time we are sending up an okay request.

07:48.390 --> 07:53.340
So 200, everything is okay and then I can chain on a dot send and everything like that.

07:53.340 --> 07:58.950
If I save this you can see server is still up and running and our browser is not going to make any difference.

07:58.950 --> 08:01.140
And that's where the postman comes in.

08:01.230 --> 08:05.010
This is exactly the time where you see that what request comes up.

08:05.010 --> 08:07.260
So let me go ahead and fire up my postman.

08:07.350 --> 08:08.370
And there we go.

08:08.970 --> 08:11.430
It's going to take a little bit of the time.

08:11.430 --> 08:12.480
There we go.

08:13.380 --> 08:15.420
And come on, you can do this.

08:16.550 --> 08:17.850
And I'm going to just open up a new.

08:17.900 --> 08:18.470
Just open up.

08:18.470 --> 08:21.230
Just close all of these guys and just open up a new tab.

08:21.230 --> 08:23.000
And it will open up a new request for you.

08:23.030 --> 08:26.840
You might be up here somewhere and just click on this plus icon and you'll be getting that.

08:26.870 --> 08:30.370
Let's go ahead and use the local host for 1000 and a slash.

08:30.380 --> 08:32.450
And of course, you can choose all of your get posts.

08:32.480 --> 08:37.390
There is a whole lot that it allows you, but we'll be just going for the get as soon as I send this

08:37.400 --> 08:43.220
the notice here it says here, start us 200 OC and it says a response of Hello World.

08:43.250 --> 08:47.770
Now let's go ahead and try to change this response to just see that RV on the same page or not.

08:47.780 --> 08:53.120
If I go ahead and say 201, which is not really an ideal status code in this case, but if I try to

08:53.120 --> 08:58.550
go ahead and send this now, I say to a one created now nothing has been created, but I told you,

08:58.550 --> 08:59.960
nobody's stopping you to do so.

08:59.960 --> 09:04.850
But this is where the status code is responsible and where it is being used at the time.

09:04.850 --> 09:09.980
When somebody is working on the front end, they will be proceeding further based on the status code.

09:09.980 --> 09:14.420
If the status code is 400, there's no point of moving further because something is wrong.

09:14.420 --> 09:19.490
If the status code is 200, that means everything is okay and I can proceed further off however I have

09:19.490 --> 09:20.270
planned on.

09:20.270 --> 09:25.220
So status code are really important and it is recommended that if you're creating a pro grade or production

09:25.220 --> 09:28.700
grade application, you should always put the status code.

09:28.820 --> 09:29.980
That's it for this video.

09:30.020 --> 09:31.520
Let's catch up in the next one.
