Everyone will come back.
So in this video we're going to be talking about something called the resource method chart.
When building a restful API and this is a very nice way to sort of organize your your head just before
you start coding the restfully API.
So we're going to be building the next video a very basic API.
So the objective is to build a rest for API that supports four operations plus minus.
Divide and multiply.
Right so the user was houndstooth numbers and we would perform one of these operations on them.
And then when we did return the response.
Now so far we're so with.
We've been talking about the get method in the post method but we also see a lot when building restfully
as put and the don't need you know method.
Off off off request so get to as we said is to get her a resource and we're going to talk about what
our resources but we usually think of that as we're getting some resource that the server offers.
On the other hand post is used to send some information to the servers or if you have a server here
then you're posting some information from your browser from another server you're posting some information
to the server and expecting a response based on that post.
Now it is a bit similar to post but it's telling the server that when you post this information this
is a big general right.
You're sending some information to the server.
Right.
But why.
Like why are you posting this information.
And you really need to create something new right.
Usually we use a post to create something new and then could use to update whatever we created.
Right.
So if we created something in the first time when we post this let's say for example you're signing
up as a user.
See the first time a user signs up he would post his information to the server.
Right.
Because that's the first time he you're creating these.
But let's say that user changes his e-mail her password.
Then you would use the put request to send the new information to the server.
Finally there's the Delete which is used to to indicate that you want to delete a certain resource from
the server.
And we don't really use this as much.
Most people unfortunately you write sort of mix this put and delete was posts so if they want to delete
a resource then they would post the server and saying hey you know you would like an extra field with
delete and then one for example.
So true or true right.
That means you know delete this this record or whatever.
So much people don't really use put and delete.
We will be using them in the future of videos but not for now so let's focus on get and post here now
before we start talking about our restfully and we need to understand what are resources and resources.
It really is is it to do to give you the you know the best condensation of water resources.
It's basically what you're offering.
What is this thing that your user wants to do.
What is the thing that your developer is trying to get.
So in this case our resources are a plus.
Right.
Resources are the mindless operation the division operation and the times operation.
These are the things that the you that the developer are accessing your API restfully API is trying
to access right.
These are the things that he's looking forward or she's looking forward to get it right.
OK so now that we know what our resources are it's very useful to draw our resource method chart.
And the way it looks like us at the mine here separate and the way it looks like is you write a method
and then you write a path and then used for that parameters and then I'll just write around for a year
and then on air quotes OK so method.
Basically this is one of these either get a post or put or delete a pass is oh sorry.
Should have put our resources here.
OK let's put a resource here.
Our That is where this resource is located and then used for is just a description of what this method
is going to do what this path is going how parameters are what what are the parameters that this path
is expecting.
So if you're posting two numbers you should indicate here I'm expecting X and a Y.
And then the error codes on.
Or sometimes the are they're called status codes are a bunch of status codes that you might return to
the user base and what he sent to you.
So for example you could send him the most basic one is 200 OK.
Right.
That means that this was successful but let's say he was missing an X right or he was missing y.
So you have to decide what area code to return to the user so that he understands.
Oh I missed you know an X or Y.
OK let's do this process for our API here.
So the first resource we have is a plus operation.
And then the method we would do is post right because we were sending to the to the server to numbers.
So we need X and Y and we're sending it to the server.
Let's make this resource at slash and.
And then it's going to be used for adding two new numbers.
And then we need parameters X which is a float ride or any number.
Let's keep it in for now.
So we need X which is an end in Y which is.
And finally we also need an area code.
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
one of these.
Well in that case we would return to the user.
Let's pick up Eric.
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
I'm just using a random one but we have to make sure that in the documentation we tell the user what
three or one really means to say a 3 0 1 means missing argument or missing parameter.
OK let's do the same for a minus was going to be the same.
Right so it's going to be post but this time is going to be slash subtract and then it's going to be
used for so Tracting.
So tracting two numbers and then it's also going to me expecting an X which is an end and a Y which
is an end and the error code is the status goes would be 200.
OK if it's a success.
So success or a three or one again if it's an missing barometer.
OK.
Now I'm a bit of a tricky one division one.
We're also going to be opposed.
We're going to do slash divide and we're going to be dividing two numbers.
OK.
We're also going to be expecting an X which is an int a Y which is an end and rabbanim you were their
sponsor goes.
Give me 200.
OK.
Right.
If if everything went OK but then this time we also might be missing a number.
So it might be three or one right missing parameter but then this time what if the user sends Y has
zero.
So we're doing we're doing X or Y Y if y is zero then that went crash on our server.
You don't want that.
So we should always check for that and we say 3 0 2.
Why is 0 right out.
Okay.
Finally multiplication is going to be somewhere under addition subtraction right.
Because there's nothing extra to be careful about it and are in in multiple is toast slash multiply.
You know it's going to be X times Y and then we're expecting x and y which are both integers and again
two hundred four.
OK.
And 3 1 for any missing parameters or worse this is missing.
Parameter.
OK.
So now to make sure to make sure we were OK with this.
200 is OK.
Three or one is a missing parameter.
So we're missing some parameter and 3 0 2 means.
Why is zero.
So why is 0 200 is OK and 3 tier 1 I guess is a missing parameter.
So this whole structure over here is called the resource
chart or a resource method chart and it's basically used to you know summarize what your API is going
to be and helps you later on when you're coding and we're going to look at this.
Several times after that.
Yeah that's that's basically what a weather or resource method chart is.
So in the next video we will start implementing this restfully API and Schloesser and we're going to
see how we can make sure all these things are true.
So until the next video decoding.