Memi: Okay,
so, we've talked about API,
about web APIs,
we talked about the different types
of web API,
and now it's time for REST.
So, what exactly is REST?
As mentioned earlier,
REST is an acronym,
stands for "Representational State Transfer".
Now at this point,
you probably scratch your head
and ask yourself,
"What the?"
Well, hell, yeah,
I did it too,
the first time I met this strange expression.
But there is some logic in it,
and here is an explanation in some simpler English.
So what this definition means,
is basically that,
REST API enables transfer
of representation of a resource's state.
Now note, the utilized words;
we are discussing here
transfer of a
representation of the state.
And let's explain exactly what it means.
Let's say, we have a client and a server;
now as we mentioned before,
REST, like similar web APIs,
works in a request response model.
So what happens is this,
the client sends a request
for the server,
and asks for a resource's state.
Now, let's understand what exactly a state is.
So, we define state
as the current resource properties,
and or,
the result of an action on the resource.
So in our case,
let's say that what we are looking for
is order number 17.
So we basically ask for the state
of order number 17,
which means we ask for the resource properties
the order properties,
such as when it was made,
who is the user,
what are the items in the order, and so on.
So, this is the state of the order.
What we get back from the server
is a response containing the resource's
state representation.
So the server basically send us the resource,
or the state of the resource,
in some kind of representation.
So the response represents the state,
in some way,
usually JSON, as we will see later.
So, in our example,
this is what we get;
we get a representation of order number 17.
Now, let's look at another example.
Let's say, that the client sends a request
to delete a resource.
Before we asked to see,
or to get the resource,
now we ask to delete it.
And what resource will you want to delete?
We want to delete, again, order number 17.
The server, this time,
responds with, again,
the resource's state representation
which contains a status.
And the status tells us
that the resource has been actually deleted
just like we asked for.
So these are the basic components of REST;
we see here is the resource,
the state, and the transfer.
The transfer is the transfer of the state's representation
between the client and the server.
The state of the current properties,
or the current state of the resource,
and the representation is the way
the state is represented.
Now, all this is quite theoretical,
what happens in the real world,
or in other word,
what happens when we want to implement
an actual REST API?
So in this case, we will use, usually,
the HTTP protocol.
And, how will the request
and the response look like using HTTP?
Well, like this,
the request will look something like,
"GET/api/order/17"
and the response is a number,
in this case 200, and "OK",
and some kind of JSON.
Now, later in this course,
we will deep dive into each component of the request,
and the response.
So, don't worry
if you don't understand exactly what is going on here,
but suffice to say,
that this is a general representation
of the request and the response,
over the HTTP protocol.
And now, let's deep dive
into how a request and the response look like,
in REST.