Everyone so in the last year or year we stop at installing postman and we tried posting some information
to the server and last but it ended up you know telling us the method you know was not supported Glubb
of MTS was checked here.
So the message is not allowed the require request and you're out.
So let's try and fix that.
So in this video we're going to be sending to an average.
X and Y and then we're going to make the server add them for us and then reply us with the weather response.
So let's see how we would do that.
So first of all we need to define an end point for the server to hit.
So I'm going to choose the end point as it's slash and to not.
OK so I'm going to add two numbers.
But this time we're going to add something after the name.
We're going to add methods is equal to post.
So what does this mean here.
It means that the message that this function should be allowed to handle is on the coast.
But I can also add here get.
So that means that this function should support only get now by default.
Any function defined like this has methods equal get in it.
So you don't have to add extra get.
But if we find the post then we override it.
So now this function would only accept a post request.
And if you try to send them a request you would.
It would give you the same error here.
This method is not allowed for the requested euro.
So we're saying we're only going to be allowed to post messages to hit this end point.
OK so now we're going to have to find just any functions to add to the numbers.
And now let's think about a bit about some about what we want to do.
First thing is we want to get x and y from the posted data.
That's step one step two would be to add X plus Y and story and Z.
And Step 3 is to prepare adjacent and then it have the field and zent and then the song as Zed.
OK.
And that's it.
And then Step 4 is return.
Jason if I was Jason ify and then the Jason that we prepared or the map that we prepared map prepared.
OK so let's take this step by step.
First of all we need to get x and y which were posted from the data.
So how do we do that.
Well we first need to get the D.
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
from Plaskett important flacid use on site and we're going to introduce a new one called request.
Quest has all that nice information about the posted data that has come to this function over here.
Now once you are here we're going to say Data Dictionary is equal to request and then doesn't get Jason
so it has a function called get Jason and that's about it.
So let's try to see what happens.
Hi Jason as I did I'm Dictionnaire.
OK so let's try and see what happens when when this thing over here happens.
So let's let's say this right and then run a flask and then go here and then change this to.
And that's what we call it.
And to add two numbers and then if we send it we're going to get exactly the posted data that we got.
So here we got x 1 y to this is what we send the server.
And this is what we sent back.
This is actually the Jason that we want.
So that's great.
We have received it.
So that means that this data dictionary has an x and y that we want.
Great.
OK.
So now you want to say that x is equal to the data dictionary and then the field is called X because
here you were posting the field X..
Next you want to define y.
So why is equal to the data dictionary.
Why.
Right because here we have to find x and y.
Now finally you want to define zed as x plus y and then we're going to prepare the return Jaisalmer
and it's going to be Zad.
And then the value goes.
And finally we're going to return your satisfy the return Jason and that's about it.
We got that posted data.
We did some computation here and we're going to apply the response which is there are Jason we've prepared
it and then we're going to return it.
Now how do I tell the requestor that this is a success.
Well if you remember the last video we said we want to send the request with a status code of 200 which
means success 404 means not found 200 means success.
So I'm going to add a comment here and then I'm going to say to the user two hundred which means success.
And then I'm going to receive and then see what happens.
So I'll stop flask.
We are on it and then we'll see what happens when we send or request again.
Well we get it.
Finally here we get Zed and then three three is the.
What happens if we try.
And then if we look here we're going to see that the return status code is 200.
And we got a post at this location here.
Now what happens if we you know just play along with the numbers 100 200 So that's 100 plus 200 300
obviously.
So we send the request and we got three out.
So basically built up very many tiny API that adds to numbers where the users send the input there.
And then you return the response.
Now obviously we're doing a lot of assumptions here.
The first assumption is that we're trusting that the user is going to send in x and y.
So what happens if the user doesn't send us x and y.
What happens if we do this.
And then just post this information.
Well we'd actually send that we get a 400 request and we should really be very careful when we're implementing
it.
Our You know we shouldn't really trust the user to send to always they're missing.
So we have to you know here we're really trusting the user.
OK I know he's going to get x y.
We should always check you know check is X in data dictionary or not.
And so.
So not in the dictionary then we would probably return you know error or this wouldn't be Y.
So let's change this to Y.
And then for example area code 3 0 5 example.
And so when we restart.
And then we send.
This time it won't crash our server but instead it's going to tell us OK you know different there and
so on.
So it's always better to do you know send basically was it cold to to handle these types of errors before
you send these requests.
So yeah that's it for the first session.
Really what we've been doing here is to get familiar with these type of host requests.
Jaison you know slash by or are get requests responses.
You know it is a take away from this section really as you should know what get request post request
what are requested is what a post is request is what our response is what a status code code is because
these will be used a lot in future videos.
So yeah.
Thank you for watching this video and I'll see you in the next videos.