-: So the "get" verb,
as we mentioned earlier
get is used to retrieve resources.
Which means you should never use it to add
or update or delete resources.
It should be used only for retrieval.
Now it might retrieve a single resource,
or many resource, or not at all
if no resource is found according to the parameters.
But again, you should never use it
for any other types of actions.
Now, what important to know about the "get" verb is
that this is a default verb of the browser.
So if you type an address in the
in the address bar of your browsers and hit enter,
then the browser sends a "get" action
with the URL, of course, to the server.
And this is what the server executes: a "get" request,
We will see that in a minute.
Now "get" request are usually combined
with parameters so the server will know what
kind of resources it should retrieve.
It's not a mandatory and we will see some examples
which will not use parameters,
but sometimes you will find them.
If you remember we mentioned earlier that a rest
request is comprised of four components, the method
the URL, the headers, and the body.
Now a "get" request should not include body.
All the information the server needs
in order to execute the action is included
within the method and the URL.
The server should not require any other information
beside the method and the URL.
Okay, and now let's demonstrate the "get" request.
So first, remember that we say to the browser
by default send a "get" request from the address bar.
So let's see this happening.
So this is a quite standard Chrome browser
and I want to launch the developer tools.
If you are familiar with Chrome's developer tools
that's great and if not, nevermind
we are not going to deep dive into them.
So, click F15
and you will see this small window open
at the right hand side of the screen.
Now, make sure that the network tab is selected
and now go here and type whatever others you would like.
I will go again with google.com and "enter"
and see what's happening here.
So what we see here is the recording of all the requests
that the browser made.
Of course it asked google.com and then there will some kind
of JavaScript files and icons and images and then
many other things.
But we will focus only on the field request,
which is google.com.
So click it here and what we'll see here is a quite
detailed description of the request and the response.
And the thing that really interesting for us is this;
The request method is "get", so even though the word
"get" is not written anywhere in the, this is what
the browser sent to the server, we can also
see the status code, which is 200
and we already know that 200 meaning okay
Great, so we saw what the browser is doing.
But what is really interesting for us is of course
the REST API.
So let's go again to the Beeceptor for our page
that we built with our sub domain.
Again, my Sub domain is API course.
You probably selected other Sub domains
and we will start building a new API.
So again, let's go here to the mocking rules and click it
and we will create new rule.
So what are we going to do here?
With the method we are going to stay with "get",
this is a verb that we are discussing in this lecture.
And here in the API URL I will define the following API.
So this will be forward slash API forward slash order
and I'll just modify the response body to be "order"
And We will create another object here,
another JSON object
and we'll call it,
we'll call this one, sorry
order date and make it
12/12/2018.
And order user, which is a user that made the order.
And let's say it was user number 17 and close this one.
Close this one, great,
and let's save the rule.
But before it, just remember this part forward slash API
forward slash order.
And save all, Great, let's close this window
again copy this part so you will be able to access API.
So control C.
And now let's go to Postman right here.
And I bring it from auto screen.
So here I've already have the prefix
so all I need to do is simply change test to order.
So this is the API that we created in Beeceptor and send.
And this is what we've got
and this is exactly what we were expecting.
If you got anything different than that
some kind of error message or things like that
then be sure that you used the same verb.
It would be "get" make sure that the URL is correct
and also, double check the JSON that you typed in Beeceptor.
So just so we will remember it,
this is what you should see in the response body.
If you see anything else, then maybe the JSON is malformed
and can't be validated and returned.
Okay, great.
So we've built our first "get" request.
Now there is some limitation to get requests.
For example, the length of a "get" request is limited.
Now the limit itself is varied by browser and by server.
So there is no definite number
that all servers and browsers are compliant with,
but it usually somewhere around 1000 or 2000 characters.
Now let's demonstrate what's happening
when sending a too long "get" request.
So I do something like this
and I'll take it and copy it to make it quicker.
I have no idea how many characters are here
but there are definitely a lot.
And let's add this again and send.
Okay. And now look at the response
that we've got from the server.
We've got a very nicely formatted message
actually HTML formatted, and it basically tells us
that the URI is too large.
And you can also see here the status code.
Status code is 4 1 4, meaning the URI is too large.
So you should always keep in mind
that there is a limit for the length of the "get" request
and make sure not to send too long requests.
Now this limit begs a question,
what happens when the query contains too many parameters?
For example, let's say I have a list
of items of 2000 items and I want to retrieve them.
So in this case, I will have to send this list
this giant list to the server
in order for it to send me back the items.
However, this giant list with all its 2000 items
is simply too long to be sent using "get".
So what should I do in this case?
Well, in this case we can use the post verb
which we will talk about in a minute.
So it's true
that post is not targeted towards retrieval actions
but in this specific case we don't have any other choice.
So when dealing with a long list of parameters
which can't be sent using a get is an use POST.