Hey, everyone, and welcome back to the Knowledge Portal Video series.
Now, continuing our journey with the get method will be speaking about conditional get in today's lecture.
So let's go ahead and understand more about this.
Now conditional get method is used to fetch information.
However, with a specific condition.
So in this example we have a get method which is get slash sample dot HTML for the http 1.1 protocol.
Host is Dexter labs in and a condition which is specified over here is that if modified since.
So this is the header and there is a date and time associated.
So you have if modified since Saturday, 18th October 2017 at evening, 7:00 and 43 minutes and 31 seconds
of GMT time.
So what this basically says that get me this file only and only if it is modified after this specific
time.
If it is not modified that, then do not really need the file.
I just need the file if it is modified or if it is updated.
So this is the basic about conditional get.
Let's get back to our labs and we'll understand this specific value.
So when you do a curl on Dexter labs dot in slash sample dot HTML this time I'll do a hyphen I so that
we can see the response headers.
And within the response header there is a very important header called last modified and followed.
The value associated with this header is Wednesday, 18th October 2017 at 5:00, 19 minutes and 43 seconds
GMT.
So this response header basically tells us on what was the last time this file sample dot HTML was modified.
Now this is a very important header because if a browser is or if a user is trying to load this file
again and again, and if the file is not modified, what a browser can do is browser can store this
file in cache and it can only supply the newer version.
If this last modified date has been updated.
We'll be discussing this in the upcoming lectures.
But for the time being, let's do one thing.
Let's do a curl and I'll say Dexter dot P labs dot n slash sample dot HTML.
So this time I'll get a response, which is of two lines.
This is sample sample file and it is specifically designed for get request.
Now we'll add an additional header with hyphen hyphen header.
And this time I'll add a header if modified since.
And we'll put a value which is present over here.
I'll paste it and I'll press enter.
Now here you will see you did not really get any response.
Now, the reason why you did not get response is because the file is not modified after this specific
time that we have mentioned over here, if the file gets modified after this date and time which is
specified, then the response will be received.
So let's try one thing instead of 519.
I'll say 518 So just a minute back and I'll press enter.
And now you'll see I got the response back.
Now, the reason why I got response is because the file was modified after this specific time interval
that we have been writing in our header file.
So if you look into the headers, let's do one thing.
I'll put hyphen I so in hyphen I you are getting the response because file was actually modified at
519.
Now if I do 519 back here again this time instead of 200.
Okay, you will get 304 not modified.
So the web server is saying to the client that the file has not been modified after this specific amount
of time and thus the response is not received.
The contents of this file is being not received, and this specific conditional plays a very important
role during the caching process of browsers.
So this is the basic about the conditional get.
I hope you got what a condition basically means.
So this specific condition is something that we are specifying.
Like if this condition is met, then only send us the file.
If condition is not met, do not send me the file.
So this is what the high level overview of the conditional get really means.
So this is it about this lecture.
I hope this has been informative for you.
Again, if you have any doubts suggestions, feel free to connect us at Twitter, Facebook or LinkedIn
or mail us at instructors at the Rate Labs dot n.
Thanks for watching.