WEBVTT

00:00.080 --> 00:00.650
Hi everyone.

00:00.650 --> 00:01.250
Welcome back.

00:01.250 --> 00:05.960
In this lecture we'll learn about the simple web server that's part of Java.

00:05.990 --> 00:08.390
This was released as part of Java 18.

00:08.390 --> 00:12.620
And it's part of the Java distribution that we installed in our machine.

00:12.620 --> 00:17.000
This web server serves the files and folders from your machine.

00:17.000 --> 00:17.990
That's all it does.

00:17.990 --> 00:19.670
Nothing more, nothing less.

00:19.670 --> 00:25.340
Probably you might have this question running in your head, why is this being released in Java in the

00:25.340 --> 00:26.000
first place?

00:26.000 --> 00:32.960
So the primary goal of this simple web server is that can be used for prototyping, testing and debugging.

00:32.960 --> 00:35.810
So how do we launch this simple web server in your machine?

00:35.810 --> 00:41.180
We can launch the simple web server by running the J web server in the terminal.

00:41.180 --> 00:46.550
So when you run this, this is going to automatically launch the web server that's going to be serving

00:46.550 --> 00:48.650
up the files and folders from your machine.

00:48.650 --> 00:53.090
And some of the things that you need to be aware of when it comes to J web server is that it has the

00:53.090 --> 00:56.810
support for just the get and head requests only.

00:56.810 --> 01:05.470
The next thing is Https is not supported, and it has just the support for HTTP 1.1, which means http

01:05.470 --> 01:05.680
t.

01:05.770 --> 01:11.050
2.0 is not supported, so that's all you need to know from a theoretical aspect of it.

01:11.050 --> 01:13.390
Now let's go ahead and explore this in action.

01:13.390 --> 01:16.990
So in this case I'm going to go back to the terminal or to my IntelliJ.

01:16.990 --> 01:22.420
So in the IntelliJ if you open your Explore Java Features project and then if you go to the resources

01:22.420 --> 01:22.960
directory.

01:22.960 --> 01:25.360
So in the resources directory you will notice two files.

01:25.390 --> 01:26.920
Number one is movies JSON.

01:26.920 --> 01:31.240
So this movies JSON returns you an array of different movies actually.

01:31.240 --> 01:35.710
And if you take a look at it, it has ten movies in this particular JSON file.

01:35.710 --> 01:39.040
And then you have another file named movie ID by JSON.

01:39.040 --> 01:40.780
So this is a one single file.

01:40.780 --> 01:42.940
So this is a single JSON element.

01:42.940 --> 01:46.270
That's the reason why the name is movie ID by JSON.

01:46.270 --> 01:52.180
So what we are going to do here is that using the J-web server we are going to be serving up these two

01:52.180 --> 01:52.930
Jsons.

01:52.960 --> 01:53.200
Okay.

01:53.230 --> 01:55.330
And then we are going to look at it in the browser.

01:55.330 --> 01:56.590
So the very first thing is.

01:56.590 --> 01:58.960
So I'm in the root path of this specific project.

01:58.960 --> 02:00.930
In this case, you can see the modern Java, right?

02:00.960 --> 02:02.670
That's where I'm on right now.

02:02.670 --> 02:06.270
And then what I'm going to do, I'm going to run a J web server.

02:06.300 --> 02:10.740
If you run this command, what this is going to give you is that this is going to be starting up the

02:10.740 --> 02:12.870
web server in the port 8080.

02:12.900 --> 02:15.600
As you can see, it is running in the port 8080.

02:15.600 --> 02:22.080
And what it is telling you here is that serving the content under modern Java and the subdirectories

02:22.080 --> 02:27.360
on port 127.0.0.1 and port 8080.

02:27.390 --> 02:30.300
Okay, let's copy this and then let's go to the browser.

02:30.720 --> 02:34.650
So in the browser I'm going to hit this endpoint.

02:34.650 --> 02:39.540
So if I hit this endpoint this is exactly what we have in our IntelliJ actually.

02:39.540 --> 02:44.040
So if you go to the IntelliJ you have this check out service Explore Java features.

02:44.070 --> 02:47.460
So you have the check out service here you have the Explore Java features here.

02:47.460 --> 02:50.400
And then you have the modules folder here.

02:50.400 --> 02:52.500
And then the Readme Gradle.

02:52.650 --> 02:58.590
You see right the Gradle over here we have the readme and then we have the settings.gradle dot CSS.

02:58.620 --> 03:01.470
All those files are hosted in this web address.

03:01.470 --> 03:07.410
And now what we are going to do is that we are going to be hosting the movie ID by Jason and the movie

03:07.410 --> 03:09.420
by our movie star, Jason.

03:09.420 --> 03:14.160
So if you go to the actual resources directory in the resources directory, I have all these commands

03:14.160 --> 03:15.090
readily available.

03:15.090 --> 03:22.890
So if you go to the commands dot, txt so you can actually copy this and then hit this endpoint from

03:22.890 --> 03:23.460
the browser.

03:23.460 --> 03:24.330
So if you hit this one.

03:24.330 --> 03:24.840
So there you go.

03:24.870 --> 03:29.580
It gives you all the movies that's been present in this specific directory okay.

03:29.610 --> 03:37.470
And then in this case if we hit movie ID by Jason it's going to just serve up that specific file.

03:37.470 --> 03:42.690
And let's say if you just provide the resources over here, it's going to serve up all the files in

03:42.690 --> 03:44.310
this specific folder.

03:44.310 --> 03:50.370
So the J-web server is useful if you have any kind of testing going on where you are building a UI.

03:50.370 --> 03:52.380
And the UI requires a simple JSON.

03:52.380 --> 03:58.070
So in those kind of scenarios, basically you can use J-web server to host those files, and you can

03:58.070 --> 04:00.200
prototype your UI based on that.

04:00.200 --> 04:05.690
Or it could be a back end service, require some kind of a response from another service, but the other

04:05.690 --> 04:06.950
service is not ready yet.

04:06.980 --> 04:12.530
You can simply use your server to give you the response whatever you want through an endpoint call like

04:12.530 --> 04:12.890
this.

04:12.890 --> 04:14.750
So we have this option available.

04:14.750 --> 04:20.360
So any time you are looking for a real network call that can serve up a JSON or any kind of content

04:20.360 --> 04:26.960
over the network, then you can use the simple web server by running the J-web server command like this.

04:26.960 --> 04:29.330
And then it can serve up the files and folders.

04:29.330 --> 04:32.600
In this case, any call that's been made, it will be logged over here.

04:32.600 --> 04:36.530
So in this case, if I hit this one more time and you'll be noticing a call over there.

04:36.560 --> 04:36.980
There you go.

04:36.980 --> 04:38.930
So all these calls get logged to.

04:38.960 --> 04:40.640
So that's all about simple web server.

04:40.640 --> 04:45.860
In the next section we are going to be exploring the new HTTP client that got released as part of modern

04:45.860 --> 04:46.280
Java.

04:46.280 --> 04:51.830
And we will be using the web server as a back end for that HTTP client, which is exactly the purpose

04:51.830 --> 04:53.420
of the J web server.

04:53.450 --> 04:54.920
This marks the end of this lecture.

04:54.920 --> 04:56.270
Thank you for watching.
