I HAVE ROOM.
Welcome back.
So in this video we're going to be starting to work on a project of.
So so what we've been dealing with Baby Eyes that add subtract divide and multiply numbers and usually
no one would you know.
No.
Most developers wouldn't call and maybe just add two numbers right unless they're like super huge rise
and usually be what people would do is they just use the addition or a division in their in their original
programming language that they're using to develop something right.
And so it doesn't really make our API doesn't really isn't really concrete or is it really practical
person.
But we are now going to start moving into a slightly more flexible API.
So for now we're just going to comment on all of this already.
From now from from from this moment on we're going to comment this on we're going to refences sometime
soon so I don't want to delete it because we might copy some code from here but for now let's just copy
this and we're going to write a new application.
And now like this idea this application is going to be very simple.
So we have a couple of free user requirements if you think about it.
Now the first thing is we have to allow registration off a user.
OK.
So this is one of the most important thing in an API you want to make users be able to register into
your API.
Right.
The second thing is we want the user to have the ability to store a sentence on our database for one
token.
So for starters they each user is going to get 10 tokens so each user say right here each user gets
10 tokens.
OK.
If the user stores a sentence on our database he uses one token and he can also retrieve.
OK so you can retrieve as his short sentence door sentence on our database for one to open.
OK.
So there's two dives right there's 1 1 2 and 4 to store a sentence on the database and one one token
to retrieve Histoires and sentence right so you can store something on our database and in return for
storing something on our database.
I will take a token for him.
And basically you can think of these tokens as something you might be selling right you might be an
API business who is trying to sell to users like OK buy a hundred tokens for maybe $1 or $2 right.
So you're allowing the user to use these and tokens to access your service right to access your API.
So we're going to allow the user to register and that's of course zero tokens right and that's for free
and that each user gets 10 tokens.
So that's tokens over here and store a sentence for one token and retrieve his stored sentence from
our database for one too.
Now a couple of things we're going we're going to be doing password and user name storage.
So we're also going to be talking about a lot of stuff like password hashing and salting and all that
stuff.
So that should be exciting.
And by the way when we're done with this API hopefully should looked similar to an API you might see
in the market right.
Some some you might have heard the name off the database as a service or some services actually offer
you an API just to store stuff on their database and they charge you for some money right.
So this is the same idea but on a much smaller scale so we're only allowing them to store like a string
not a file.
Nothing huge just a tiny string onto our database.
And then he might pay for one too.
OK.
So first of all we're designing an API.
We're designing a brand new API so we want to have a chart protocol on shorts.
Let's go here and start working on join.
OK.
We're going to be drawing the chart that we usually do when we start working on a new API.
OK so we have a couple of them and we have a resource if you remember we have the resource app and then
we have the address of that resource where is going to be at.
And then the type of the source of the protocol and then to prove to CO.
Right.
And then parameters.
What parameters are we going to take.
And then responses.
Okay so how that our response is going to be plus data is good right.
What status codes are we going to use.
Okay.
Okay so let's divide this year as do this line hopefully.
Not too bad of a line right now not to straight.
And then we're dividing this into a table.
Okay.
And then a line over here.
So the first resource that we want to support is we're going to support 3M.
So the first one is to register I user.
Right so this is the first resource that we should have in our API.
And so the actress might be at slash register for example now since the user is going to be sending
us his username and password that he wants to register with.
Then this is going to be post right.
We need to get information from his for his username and his desired password from here from from the
posted data.
Right so we're going to do post because we need the body to sign with his information and we should
expect do things right we should expect a username username and password so I'm just going to write
P.W. and both of them should be strings right strings.
Now what about the response codes.
Well there's Fosco to your mind be 200.
OK.
So that means that you're registered successfully or you might be some other numbers right we want to
make this API very simple.
So you might add here something like 301 which means that his response for example his password was
very weak.
Right.
So you don't hate choose another password.
But for now we're just going to take.
You know I saying that the user is smart enough to choose a good password and not a bad password.
I said we'll just leave the status quo as 200 for now.
OK so that's the first resource.
The second resource we're going to cover is to store a sentence right store sentence.
And as you might have guessed the third one is going to Zola's do a line here.
And the third one is going to be retrieve sentence.
OK.
So a store sentence is going to be at slash or and then they retrieve sentence let's just do it.
Ask lasht get right get Give me my sentence right.
So the storewide So the slash get one should you.
This is it should be obvious from your IT SHOULD BE A get right because we want the information right
where we're telling the server Hey give me my sentence back.
So it's again we're just getting the protocol.
We're just getting the resource.
Whereas in store I'm sending the server my sentence I'm telling you hey I want you to store my sentence.
So this is going to also be a post and for the parameters we are going to need a couple of things right.
We want to make sure that the user sends his username username password and also the sentence right.
Now why does you need to do to send the user name and password.
Well imagine if I am I know that my friend is registered.
So I tell I tell you hey I'm on my friend story for me in this sentence.
And so I ended up using his own tokens even though he didn't use my service.
So I have to make sure that the person who is sent 10s.
So I have to make sure that the person who is requesting my API is actually the correct person right
before I take away one token from him.
Right.
So I have to make sure that they use your name and the passwords match together.
Now what about the response goes What about.
So I might have 200.
OK so everything went fine and you know the whole world is fine.
No problems here or I might have even 301 so 301 might be out of tokens.
So the user might be asking hey please please.
Store for me this sentence.
But he has zero tokens I'm telling him sorry you don't have enough tokens I can't store it for you you
have to buy more before you use it.
Right.
You can also have I'm just going to put it here three and two.
And that's what happens when this user name doesn't match this password right so invalid username or
username password combo combination.
So this username doesn't correspond to this Vaswani So I tell him hey you're not authorized to try to
do it to do something else and put it check your password for example.
Now this is the same thing for the retrieve sentence.
I just need his username and password.
I don't need a sentence right because that's what I'm returning to him.
And then a similar lead might have to do it.
OK.
If it's everything's fine.
My also asked 301 out of token out of tokens so he doesn't have enough tokens to retrieve his aunt.
So I tell him please buy more tokens so you can use my service or 1:57 is username and password are
incorrect so invalid username password.
OK.
So that's my political That's my idea.
That's the API that we will be building in the next video.
But for now let's just stop here.
And in the next video we're going to see how we can start building this API and how we're going to store
the stuff in the database and all that.
So yeah we'll stop here and until the next video happy going.