WEBVTT

00:05.310 --> 00:06.780
Everyone will come back.

00:07.100 --> 00:11.990
So in this video we're going to be talking about something called the resource method chart.

00:12.020 --> 00:18.890
When building a restful API and this is a very nice way to sort of organize your your head just before

00:18.890 --> 00:22.170
you start coding the restfully API.

00:22.190 --> 00:26.150
So we're going to be building the next video a very basic API.

00:26.150 --> 00:33.510
So the objective is to build a rest for API that supports four operations plus minus.

00:33.530 --> 00:34.700
Divide and multiply.

00:34.700 --> 00:39.930
Right so the user was houndstooth numbers and we would perform one of these operations on them.

00:39.950 --> 00:42.440
And then when we did return the response.

00:42.440 --> 00:44.580
Now so far we're so with.

00:44.770 --> 00:50.790
We've been talking about the get method in the post method but we also see a lot when building restfully

00:50.980 --> 00:55.210
as put and the don't need you know method.

00:55.210 --> 01:01.430
Off off off request so get to as we said is to get her a resource and we're going to talk about what

01:01.430 --> 01:09.590
our resources but we usually think of that as we're getting some resource that the server offers.

01:09.860 --> 01:15.410
On the other hand post is used to send some information to the servers or if you have a server here

01:15.650 --> 01:21.980
then you're posting some information from your browser from another server you're posting some information

01:21.980 --> 01:26.210
to the server and expecting a response based on that post.

01:26.240 --> 01:34.900
Now it is a bit similar to post but it's telling the server that when you post this information this

01:34.900 --> 01:36.020
is a big general right.

01:36.020 --> 01:38.370
You're sending some information to the server.

01:38.510 --> 01:38.800
Right.

01:38.810 --> 01:39.620
But why.

01:39.620 --> 01:42.500
Like why are you posting this information.

01:42.590 --> 01:46.020
And you really need to create something new right.

01:46.020 --> 01:54.350
Usually we use a post to create something new and then could use to update whatever we created.

01:54.350 --> 01:54.860
Right.

01:55.100 --> 01:59.840
So if we created something in the first time when we post this let's say for example you're signing

01:59.840 --> 02:01.090
up as a user.

02:01.160 --> 02:05.570
See the first time a user signs up he would post his information to the server.

02:05.600 --> 02:06.050
Right.

02:06.200 --> 02:09.170
Because that's the first time he you're creating these.

02:09.530 --> 02:12.590
But let's say that user changes his e-mail her password.

02:12.710 --> 02:19.250
Then you would use the put request to send the new information to the server.

02:19.250 --> 02:26.330
Finally there's the Delete which is used to to indicate that you want to delete a certain resource from

02:26.330 --> 02:27.040
the server.

02:27.080 --> 02:29.620
And we don't really use this as much.

02:29.630 --> 02:36.620
Most people unfortunately you write sort of mix this put and delete was posts so if they want to delete

02:36.680 --> 02:42.850
a resource then they would post the server and saying hey you know you would like an extra field with

02:42.860 --> 02:46.520
delete and then one for example.

02:46.520 --> 02:48.880
So true or true right.

02:48.980 --> 02:52.460
That means you know delete this this record or whatever.

02:52.460 --> 02:54.850
So much people don't really use put and delete.

02:54.860 --> 03:01.880
We will be using them in the future of videos but not for now so let's focus on get and post here now

03:01.910 --> 03:08.420
before we start talking about our restfully and we need to understand what are resources and resources.

03:08.420 --> 03:14.970
It really is is it to do to give you the you know the best condensation of water resources.

03:15.060 --> 03:17.100
It's basically what you're offering.

03:17.360 --> 03:21.410
What is this thing that your user wants to do.

03:21.560 --> 03:24.890
What is the thing that your developer is trying to get.

03:25.040 --> 03:28.510
So in this case our resources are a plus.

03:28.510 --> 03:29.060
Right.

03:29.490 --> 03:34.370
Resources are the mindless operation the division operation and the times operation.

03:34.370 --> 03:39.860
These are the things that the you that the developer are accessing your API restfully API is trying

03:39.860 --> 03:40.850
to access right.

03:40.910 --> 03:45.870
These are the things that he's looking forward or she's looking forward to get it right.

03:46.220 --> 03:53.560
OK so now that we know what our resources are it's very useful to draw our resource method chart.

03:53.630 --> 04:00.570
And the way it looks like us at the mine here separate and the way it looks like is you write a method

04:02.180 --> 04:14.710
and then you write a path and then used for that parameters and then I'll just write around for a year

04:14.760 --> 04:22.430
and then on air quotes OK so method.

04:22.480 --> 04:32.660
Basically this is one of these either get a post or put or delete a pass is oh sorry.

04:32.780 --> 04:35.070
Should have put our resources here.

04:35.470 --> 04:37.930
OK let's put a resource here.

04:38.100 --> 04:46.540
Our That is where this resource is located and then used for is just a description of what this method

04:46.540 --> 04:53.090
is going to do what this path is going how parameters are what what are the parameters that this path

04:53.110 --> 04:53.990
is expecting.

04:54.040 --> 04:59.860
So if you're posting two numbers you should indicate here I'm expecting X and a Y.

05:01.030 --> 05:02.270
And then the error codes on.

05:02.350 --> 05:07.900
Or sometimes the are they're called status codes are a bunch of status codes that you might return to

05:07.900 --> 05:11.170
the user base and what he sent to you.

05:11.170 --> 05:15.360
So for example you could send him the most basic one is 200 OK.

05:15.370 --> 05:15.610
Right.

05:15.610 --> 05:21.870
That means that this was successful but let's say he was missing an X right or he was missing y.

05:21.910 --> 05:25.710
So you have to decide what area code to return to the user so that he understands.

05:25.750 --> 05:28.800
Oh I missed you know an X or Y.

05:29.230 --> 05:33.030
OK let's do this process for our API here.

05:33.040 --> 05:36.290
So the first resource we have is a plus operation.

05:36.610 --> 05:41.930
And then the method we would do is post right because we were sending to the to the server to numbers.

05:41.950 --> 05:45.770
So we need X and Y and we're sending it to the server.

05:45.910 --> 05:49.690
Let's make this resource at slash and.

05:50.830 --> 05:56.290
And then it's going to be used for adding two new numbers.

05:57.250 --> 06:03.130
And then we need parameters X which is a float ride or any number.

06:03.220 --> 06:05.180
Let's keep it in for now.

06:05.290 --> 06:08.790
So we need X which is an end in Y which is.

06:08.820 --> 06:14.060
And finally we also need an area code.

06:14.200 --> 06:20.980
So if we have 200 if we send back to the user 200 it's fine but let's see what happens if he's missing

06:20.980 --> 06:22.220
one of these.

06:22.630 --> 06:25.000
Well in that case we would return to the user.

06:25.000 --> 06:26.340
Let's pick up Eric.

06:26.490 --> 06:32.230
So if he's missing one of them let's return to the user 3 0 1 and this is not a particular area code

06:32.260 --> 06:37.680
I'm just using a random one but we have to make sure that in the documentation we tell the user what

06:37.690 --> 06:46.010
three or one really means to say a 3 0 1 means missing argument or missing parameter.

06:46.810 --> 06:49.680
OK let's do the same for a minus was going to be the same.

06:49.680 --> 06:57.070
Right so it's going to be post but this time is going to be slash subtract and then it's going to be

06:57.070 --> 06:59.610
used for so Tracting.

06:59.730 --> 07:08.080
So tracting two numbers and then it's also going to me expecting an X which is an end and a Y which

07:08.080 --> 07:13.970
is an end and the error code is the status goes would be 200.

07:13.980 --> 07:16.120
OK if it's a success.

07:16.120 --> 07:21.390
So success or a three or one again if it's an missing barometer.

07:22.600 --> 07:23.020
OK.

07:23.050 --> 07:25.860
Now I'm a bit of a tricky one division one.

07:26.010 --> 07:27.570
We're also going to be opposed.

07:27.700 --> 07:35.190
We're going to do slash divide and we're going to be dividing two numbers.

07:35.740 --> 07:36.460
OK.

07:36.460 --> 07:42.660
We're also going to be expecting an X which is an int a Y which is an end and rabbanim you were their

07:42.850 --> 07:43.630
sponsor goes.

07:43.630 --> 07:44.600
Give me 200.

07:44.620 --> 07:45.260
OK.

07:45.310 --> 07:45.950
Right.

07:46.000 --> 07:50.880
If if everything went OK but then this time we also might be missing a number.

07:50.890 --> 07:59.920
So it might be three or one right missing parameter but then this time what if the user sends Y has

07:59.920 --> 08:00.400
zero.

08:00.400 --> 08:05.610
So we're doing we're doing X or Y Y if y is zero then that went crash on our server.

08:05.620 --> 08:06.610
You don't want that.

08:06.760 --> 08:10.390
So we should always check for that and we say 3 0 2.

08:11.140 --> 08:15.340
Why is 0 right out.

08:15.970 --> 08:16.610
Okay.

08:16.810 --> 08:21.270
Finally multiplication is going to be somewhere under addition subtraction right.

08:21.310 --> 08:31.500
Because there's nothing extra to be careful about it and are in in multiple is toast slash multiply.

08:32.140 --> 08:41.800
You know it's going to be X times Y and then we're expecting x and y which are both integers and again

08:41.820 --> 08:42.850
two hundred four.

08:42.850 --> 08:43.670
OK.

08:43.780 --> 08:48.810
And 3 1 for any missing parameters or worse this is missing.

08:50.430 --> 08:52.410
Parameter.

08:53.590 --> 08:54.240
OK.

08:54.330 --> 08:58.370
So now to make sure to make sure we were OK with this.

08:58.540 --> 09:00.040
200 is OK.

09:00.060 --> 09:02.160
Three or one is a missing parameter.

09:02.160 --> 09:08.000
So we're missing some parameter and 3 0 2 means.

09:08.130 --> 09:09.640
Why is zero.

09:09.660 --> 09:17.790
So why is 0 200 is OK and 3 tier 1 I guess is a missing parameter.

09:17.790 --> 09:23.130
So this whole structure over here is called the resource

09:25.460 --> 09:35.670
chart or a resource method chart and it's basically used to you know summarize what your API is going

09:35.670 --> 09:40.830
to be and helps you later on when you're coding and we're going to look at this.

09:40.980 --> 09:44.160
Several times after that.

09:44.370 --> 09:51.990
Yeah that's that's basically what a weather or resource method chart is.

09:51.990 --> 09:56.880
So in the next video we will start implementing this restfully API and Schloesser and we're going to

09:56.880 --> 10:01.340
see how we can make sure all these things are true.

10:01.350 --> 10:03.330
So until the next video decoding.
