By everyone.
Welcome back.
So in this video we're going to be talking about what a restful API is so we always hear that term restful
API.
So we're going to be talking about what is a restful API before we build one.
Again this is not going to be you know comprehensive sense.
There are like even books about what restfully be I should be.
And we can't possibly cover everything in the scope of course but we will be talking about what really
constitutes arrest for what is what is it.
What it basically is in this video.
OK.
So let's get started.
So to begin with just to give you know a definition it's basically an architectural style architecture.
Style upbuilding API.
So that's simply a definition and you might not even know you are not sure what that really means.
Let's let's let's break it down part by part.
So what is an API.
An API is basically code that allows you to take a request
and then this code takes the request and then it does some process for you and prepares a response.
And returns this response you know it eyes are not nothing fancy or nothing you can think of a library.
Right.
When you For example in any in Python when you do you know important and then some library library right
library as you know something let's say non-P as an MP.
Right.
So we're importing non-P here as an IP.
Now you can think of Numby really as an API non-P offers you lots of functions right.
You have no and pede array and then you have you know all these hundreds of functions and you can think
that Numby takes in your request is made you do.
And Peter arrays so you're telling them hey I want an array that does this function.
And then non-P does under the hood does some computation and then it returns you a response which is
your array that you want to write.
Similarly for all these functions.
No.
He's basically offering you all its API so that you can use your give it a request and then you get
the responses.
And that's what most of our programming is really using API.
So you guys are nothing new now.
So define what an API mean is there's a very classical example where I think when you're in a restaurant
right.
So there is you know you and maybe you know your girlfriend maybe you or your wife and then think here
is the waiter.
And then here is the kitchen.
Right.
So in this context here the waiter acts as an API and the waiter takes in your request.
He says OK you want this chicken or vegetables or whatever.
And then it takes that request and then sends it over to the kitchen where and where sometimes the waiter
would cook but that's not what happens right.
You know the kitchen is where cooks.
And then once the cooking has happened then the waiter takes the response which is your dish dish that
you ordered foie gras and then takes it back and gives it back to you.
So in a way the waiter is acting really is an API.
So yeah that's just you know our classical example of what a weather API is.
So we're saying that a restful API is a method of designing API.
It's an architectural style it's one way of doing it.
Not the only way.
Style of building an API.
But it's one way.
And if you feel like this request response here is very familiar.
Well it's because when we were talking about the Web how the web was working and how DTP was working
we always said that you always do a request and then you get a response back.
Well that's the idea here.
The idea is the communication in arrest for API uses the web.
So rest for API really it's just an API right.
We're just a normal API.
But instead of using you know the on and off line version of the code you're actually using HTP or the
web to communicate with with this kitchen.
So.
So instead of having this kitchen locally.
Right.
This kitchen is in the cloud or on the web.
And then your waiter here is HTP right.
You're preparing a request to go to the kitchen using as you can be and that she gives you the response
back using a to keep your response.
So this request response pattern is basically what an API is expected to do.
And the means of communication between you and your girlfriend or wife and the kitchen is using HTP.
Right.
So in other words really a restful AB is nothing more than just a normal API just a normal library that
offers a bunch of functions for you but these functions can be consumed or can be used right.
So here I can just consume them by calling the function right.
But here in this case they're not a local library.
In this case what I do is I use HTP over the web to send a response to send a request to this API over
the web make the API do some stuff for me and then get their response back to my web application or
it or get their response back in general.
So that's basically the whole idea of a restful API restful API is you have your own server.
Right.
Let's say you're building a restful API.
So you have your server and then you open a few and boy.
So just like we did previously it is like Slash by Slash add two nuns you know slash the other.
And so on.
So you open a bunch of you know and points on your server and you say to people hey these are my points.
This is my API here.
So this is my API.
All these functions you can use by just accessing this endpoint.
So a user or a developer.
Most people who use Abiah eyes are really developers.
So let's say you're making a mobile app right.
And then the more about how you want to add you know to numbers right.
You could just add you know be calls a plus one.
Right.
It's simple.
Let's say you're using like a really crappy crappy programming language that doesn't support too.
Adding two numbers right or say even a more realistic example is let's say your function here adds really
huge numbers.
So let's say you do be equal a times two here.
This would lead to an overflow and you don't want to handle all the overflow stuff.
So you're going to leave it up to that API to add two numbers safely.
So what you do is instead of doing it because times do what you do as you do every request to that end
point and slash add two numbers and you send you know a and a right to A's so be equals daytime's two
is the same as me call a plus a right.
So you send a twice and you posted to the API twice and then that API adds it for you no matter how
big your numbers are right.
Because it handles this safely.
And then once the API is done it replies you response.
And then you just take the response and store it and b whether it's a B or you know just a training
representation of B or whatever.
Right.
So in a way instead of you know handling instead of doing for example NPE not peanuts.
And then a in a right instead if you're doing it locally you're using HGT be here to access this API
server that has a bunch of end points that act as functions and these functions do some operations for
you and return the response for you.
So this is your request going.
And then this is the response that you're receiving back and this is exactly what a KPI server is.
We are building a product for developers to use.
So let's say developers usually you know in most languages have relatively good overflow handy.
Right but one of the one of the projects we'll do in this course is we're going to build our image recognition
API.
So we're going to build that API which is made off you know slash recognize.
Right.
And then the user here is going to send us an image and we're going to apply a machine learning model
or a pre trained machine learning model and we're going to recognize or say the user sends us an image
of a panda.
Right.
So we want to get recognize it and then we're going to say going to reply to the user image with a Jason
image.
Kanda and so on.
And then the user would get this request and you know instant instead of him having to you know implement
locally all these machine learning algorithms and image recognition all the stuff with just one call
to slash recognize and giving us the photo.
He's essentially got going back.
The result of panda in which we used here the the in our server we did the computation work for him
we figured out what this photo is and we're blind to him as as a panda.
So this is the power off of API and this is why many people nowadays nobody you know does very heavy
computations like image recognition and all the stuff no one does it locally because if you do it locally
then it's really you're doing for example a mobile application then you're running this on the mobile
and mobile capabilities are nowhere near as powerful as a server.
You know it's a really bad idea to run a machine learning model on a mobo.
You know it will crash.
Oh most definitely.
So what users end up doing or what developers end up doing is they offload this this huge you know recognizer
or this huge computation required and they offloaded from the mobile app and then they offloaded to
a server a dedicated server which does all this computation for them and then replies Their response
that they need.
And this is basically what you know and a restful API here this this here is not only the API.
This is actually a restful API.
So this is basically what it restfully be eyes into the normal API.
That just supports HGP.
It's implemented using the communication means from one end to the other is just using HTP.
So yeah that's basically what a restful API is.
One last point to talk about is you know this is very very useful for developers right.
Before if you wanted to build a mobile application for example which which you know you would you would
implement some machine learning algorithms and you would have to implement this from scratch.
And this is a really bad idea.
Right.
Again you're going to be running it on a mobile phone.
Superslow you're on you're you know you're going to be doing everything offline even if you use library
libraries.
It's still going to be on the phone but now with the idea or restful API is is is that you can think
of.
So as the developer has so many API eyes on the cloud right mean not only this API but so many clouds.
And then now you can just click with one or one request he says hey give me that time.
And then this this you know maybe I convert the time for him and then he does another request.
Hey you know convert that timeframe from UTC to PSTN for example and then you convert the time for him
and then all these guys are basically like services to the developer which she can.
It's like a dream.
Right.
You have an API for everything.
So you want to numbers use an API you know even though it's it's it's not that you know doesn't make
sense to add to a numbers using an API but the you get the idea is like that you have you know machine
learning API and you have time you have you know prices let's say you want to get the prices the current
prices in in in in for example for the stocks you can get at an API for Stop prices.
So the ideas are limitless.
And in exchange for the developer for accessing this this model here this API here then the API I would
would make the developer pay a little bit of money right.
Or maybe most guys are like zero point zero zero zero one dollars per hour per call right.
So in that way the rest for API builder gets a little bit of money for the server that is running right
because this costs money race running Serbin costs money and in response the developer can code a super
hard machine learning application and just a few hours using all these you know are by offloading all
the heavy work or heavy lifting to these restful API.
So for me the idea was clear here and we're going to be discussing more about how to build restful Adrianne's
in the next video.
So until the next thing you have Piccoli.