WEBVTT

00:05.510 --> 00:12.160
Everyone so in the last year or year we stop at installing postman and we tried posting some information

00:12.160 --> 00:19.940
to the server and last but it ended up you know telling us the method you know was not supported Glubb

00:19.950 --> 00:21.770
of MTS was checked here.

00:21.780 --> 00:25.410
So the message is not allowed the require request and you're out.

00:25.570 --> 00:27.040
So let's try and fix that.

00:27.040 --> 00:30.170
So in this video we're going to be sending to an average.

00:30.220 --> 00:39.570
X and Y and then we're going to make the server add them for us and then reply us with the weather response.

00:39.790 --> 00:41.830
So let's see how we would do that.

00:41.830 --> 00:45.790
So first of all we need to define an end point for the server to hit.

00:46.030 --> 00:55.730
So I'm going to choose the end point as it's slash and to not.

00:55.890 --> 00:58.070
OK so I'm going to add two numbers.

00:58.780 --> 01:01.990
But this time we're going to add something after the name.

01:02.020 --> 01:07.310
We're going to add methods is equal to post.

01:07.450 --> 01:09.080
So what does this mean here.

01:09.100 --> 01:15.180
It means that the message that this function should be allowed to handle is on the coast.

01:15.440 --> 01:18.290
But I can also add here get.

01:18.520 --> 01:23.380
So that means that this function should support only get now by default.

01:23.380 --> 01:27.870
Any function defined like this has methods equal get in it.

01:27.910 --> 01:30.210
So you don't have to add extra get.

01:30.400 --> 01:33.510
But if we find the post then we override it.

01:33.610 --> 01:36.750
So now this function would only accept a post request.

01:36.760 --> 01:39.650
And if you try to send them a request you would.

01:39.670 --> 01:41.440
It would give you the same error here.

01:41.440 --> 01:44.370
This method is not allowed for the requested euro.

01:44.380 --> 01:50.570
So we're saying we're only going to be allowed to post messages to hit this end point.

01:50.820 --> 01:57.520
OK so now we're going to have to find just any functions to add to the numbers.

01:58.510 --> 02:03.080
And now let's think about a bit about some about what we want to do.

02:03.130 --> 02:09.990
First thing is we want to get x and y from the posted data.

02:10.930 --> 02:20.190
That's step one step two would be to add X plus Y and story and Z.

02:21.430 --> 02:33.030
And Step 3 is to prepare adjacent and then it have the field and zent and then the song as Zed.

02:33.260 --> 02:34.080
OK.

02:34.420 --> 02:35.030
And that's it.

02:35.030 --> 02:38.860
And then Step 4 is return.

02:38.850 --> 02:52.230
Jason if I was Jason ify and then the Jason that we prepared or the map that we prepared map prepared.

02:52.450 --> 02:54.750
OK so let's take this step by step.

02:54.760 --> 02:58.450
First of all we need to get x and y which were posted from the data.

02:58.450 --> 03:00.050
So how do we do that.

03:00.370 --> 03:02.350
Well we first need to get the D.

03:02.580 --> 03:08.980
Jason that was posted to us so to do that and flask we're going to go up here and we're going to choose

03:09.370 --> 03:16.380
from Plaskett important flacid use on site and we're going to introduce a new one called request.

03:16.430 --> 03:23.710
Quest has all that nice information about the posted data that has come to this function over here.

03:23.710 --> 03:36.400
Now once you are here we're going to say Data Dictionary is equal to request and then doesn't get Jason

03:36.400 --> 03:40.300
so it has a function called get Jason and that's about it.

03:40.300 --> 03:42.210
So let's try to see what happens.

03:42.260 --> 03:46.290
Hi Jason as I did I'm Dictionnaire.

03:46.330 --> 03:50.750
OK so let's try and see what happens when when this thing over here happens.

03:50.890 --> 03:59.620
So let's let's say this right and then run a flask and then go here and then change this to.

04:00.030 --> 04:03.420
And that's what we call it.

04:03.660 --> 04:11.640
And to add two numbers and then if we send it we're going to get exactly the posted data that we got.

04:11.640 --> 04:15.610
So here we got x 1 y to this is what we send the server.

04:15.730 --> 04:17.770
And this is what we sent back.

04:17.770 --> 04:20.240
This is actually the Jason that we want.

04:20.320 --> 04:21.170
So that's great.

04:21.190 --> 04:22.310
We have received it.

04:22.480 --> 04:27.070
So that means that this data dictionary has an x and y that we want.

04:27.070 --> 04:27.850
Great.

04:28.150 --> 04:28.930
OK.

04:28.930 --> 04:37.210
So now you want to say that x is equal to the data dictionary and then the field is called X because

04:37.210 --> 04:41.940
here you were posting the field X..

04:43.040 --> 04:44.690
Next you want to define y.

04:44.690 --> 04:48.320
So why is equal to the data dictionary.

04:49.210 --> 04:50.150
Why.

04:50.290 --> 04:53.730
Right because here we have to find x and y.

04:54.370 --> 05:05.760
Now finally you want to define zed as x plus y and then we're going to prepare the return Jaisalmer

05:07.700 --> 05:10.150
and it's going to be Zad.

05:10.580 --> 05:12.380
And then the value goes.

05:12.980 --> 05:22.550
And finally we're going to return your satisfy the return Jason and that's about it.

05:22.550 --> 05:24.560
We got that posted data.

05:24.560 --> 05:31.250
We did some computation here and we're going to apply the response which is there are Jason we've prepared

05:31.250 --> 05:33.550
it and then we're going to return it.

05:33.560 --> 05:37.740
Now how do I tell the requestor that this is a success.

05:37.790 --> 05:45.230
Well if you remember the last video we said we want to send the request with a status code of 200 which

05:45.230 --> 05:49.970
means success 404 means not found 200 means success.

05:50.330 --> 05:57.120
So I'm going to add a comment here and then I'm going to say to the user two hundred which means success.

05:57.500 --> 06:01.170
And then I'm going to receive and then see what happens.

06:01.400 --> 06:04.740
So I'll stop flask.

06:04.870 --> 06:10.100
We are on it and then we'll see what happens when we send or request again.

06:10.850 --> 06:11.730
Well we get it.

06:11.750 --> 06:16.780
Finally here we get Zed and then three three is the.

06:17.090 --> 06:18.420
What happens if we try.

06:18.500 --> 06:22.510
And then if we look here we're going to see that the return status code is 200.

06:22.730 --> 06:26.010
And we got a post at this location here.

06:26.420 --> 06:33.500
Now what happens if we you know just play along with the numbers 100 200 So that's 100 plus 200 300

06:33.500 --> 06:34.640
obviously.

06:34.700 --> 06:37.130
So we send the request and we got three out.

06:37.370 --> 06:45.600
So basically built up very many tiny API that adds to numbers where the users send the input there.

06:45.680 --> 06:48.320
And then you return the response.

06:48.320 --> 06:51.280
Now obviously we're doing a lot of assumptions here.

06:51.290 --> 06:57.290
The first assumption is that we're trusting that the user is going to send in x and y.

06:57.320 --> 07:01.100
So what happens if the user doesn't send us x and y.

07:01.130 --> 07:03.180
What happens if we do this.

07:03.710 --> 07:07.150
And then just post this information.

07:08.030 --> 07:16.550
Well we'd actually send that we get a 400 request and we should really be very careful when we're implementing

07:16.570 --> 07:16.870
it.

07:16.930 --> 07:22.550
Our You know we shouldn't really trust the user to send to always they're missing.

07:22.550 --> 07:25.130
So we have to you know here we're really trusting the user.

07:25.170 --> 07:27.290
OK I know he's going to get x y.

07:27.390 --> 07:34.730
We should always check you know check is X in data dictionary or not.

07:34.750 --> 07:35.660
And so.

07:35.900 --> 07:44.360
So not in the dictionary then we would probably return you know error or this wouldn't be Y.

07:44.360 --> 07:46.010
So let's change this to Y.

07:46.130 --> 07:50.530
And then for example area code 3 0 5 example.

07:50.600 --> 07:53.670
And so when we restart.

07:54.350 --> 07:55.880
And then we send.

07:55.880 --> 08:02.150
This time it won't crash our server but instead it's going to tell us OK you know different there and

08:02.150 --> 08:02.910
so on.

08:03.200 --> 08:12.140
So it's always better to do you know send basically was it cold to to handle these types of errors before

08:12.140 --> 08:15.170
you send these requests.

08:15.170 --> 08:17.800
So yeah that's it for the first session.

08:18.050 --> 08:23.740
Really what we've been doing here is to get familiar with these type of host requests.

08:23.810 --> 08:30.860
Jaison you know slash by or are get requests responses.

08:31.130 --> 08:38.400
You know it is a take away from this section really as you should know what get request post request

08:38.400 --> 08:46.250
what are requested is what a post is request is what our response is what a status code code is because

08:46.250 --> 08:49.400
these will be used a lot in future videos.

08:49.400 --> 08:49.810
So yeah.

08:49.820 --> 08:53.480
Thank you for watching this video and I'll see you in the next videos.
