WEBVTT

00:00.140 --> 00:00.680
Hi everyone.

00:00.680 --> 00:01.220
Welcome back.

00:01.220 --> 00:07.280
In this lecture we will learn about how to build the Rest client for the API that returns all the movies.

00:07.280 --> 00:07.640
Right?

00:07.640 --> 00:11.270
Which means an API that's going to return an array actually.

00:11.270 --> 00:14.930
So in this case let's copy this one over here and then go to the browser.

00:14.960 --> 00:17.540
So in the browser if you paste this URL.

00:17.540 --> 00:19.820
So this is going to give you an array of response.

00:19.820 --> 00:21.980
In this case as you can see it starts with an array.

00:21.980 --> 00:24.200
And then it has this ten movies.

00:24.200 --> 00:26.990
And then it ends with an array element okay.

00:27.020 --> 00:28.220
So now what we are going to do.

00:28.250 --> 00:32.120
We are going to write the code that's going to return a collection of movies.

00:32.120 --> 00:36.260
So so far our client that we had built returned a single movie.

00:36.290 --> 00:40.280
Now we are going to write a client that's going to return a list of movies.

00:40.310 --> 00:43.730
So in this case let's go ahead and create a new function.

00:43.730 --> 00:46.130
But the code logic is going to be pretty much the same.

00:46.160 --> 00:51.710
So in this case let's copy this and then put it over here I'm going to name this one as get all movies

00:51.740 --> 00:51.920
okay.

00:51.950 --> 00:56.750
It's not going to be Get movie by ID it's going to be get all movies.

00:56.750 --> 01:03.320
And then in the place of movie by ID URL, we will pass the all movies Movie's URL.

01:03.440 --> 01:06.560
In this case, let's pass the all movie's URL over here.

01:06.560 --> 01:12.230
So when we get the response from this client, what we are going to get is an array of movies, right?

01:12.230 --> 01:14.810
So that's going to be part of the HTTP response tool.

01:14.810 --> 01:19.940
And then in the place of body, that whole HTTP array element is going to be present.

01:19.940 --> 01:25.730
So in the case of parsing this from a single movie to an array, what we have to do is there is an way

01:25.730 --> 01:30.110
in object mapper you can actually apply the array deserialization.

01:30.110 --> 01:33.290
So in this case what we can do is there is a class name new type reference.

01:33.290 --> 01:35.420
And then all you got to do is provide this one.

01:35.420 --> 01:38.480
So this should automatically apply that logic for you.

01:38.480 --> 01:40.310
I don't think we even need this one actually.

01:40.310 --> 01:41.420
Let's go ahead and remove it.

01:41.420 --> 01:43.010
So all you got to do is do this.

01:43.010 --> 01:48.860
This should take care of automatically converting that string array into a array of movies.

01:48.890 --> 01:51.260
So in this case let's go ahead and remove this one.

01:51.260 --> 01:53.270
And then this is going to be a list of movie.

01:53.300 --> 01:56.330
So in this case it's going to be list of movie.

01:56.870 --> 01:59.990
So let's go ahead and import the necessary classes.

02:00.110 --> 02:01.100
There you go.

02:01.130 --> 02:01.670
There we go.

02:01.670 --> 02:06.650
So this specific logic is going to take care of automatically Dramatically converting a string array

02:06.650 --> 02:11.270
to an array of movies, or in this case, it's going to be a collection of movies.

02:11.390 --> 02:15.740
So in this case, what we can do, we can write a test very similar to what we did over here.

02:16.220 --> 02:17.120
Put it over here.

02:17.120 --> 02:24.320
But instead of get movie by ID, we're going to call get all movies by ID, get all movies by ID and

02:24.320 --> 02:26.390
get all movies by ID over here.

02:26.390 --> 02:29.060
So in this case, we can change our assertions a little bit.

02:29.060 --> 02:33.170
So what we can do is we know this list is going to hold ten elements.

02:33.170 --> 02:35.930
So what we can do so we can do assert.

02:37.370 --> 02:40.730
So we can name this one as movies list.

02:40.730 --> 02:45.920
And we can have movies list dot size equal to equal to ten.

02:45.950 --> 02:47.420
Okay we can do that.

02:47.420 --> 02:50.060
And then we can actually complete our assertions.

02:50.060 --> 02:55.250
This is good enough for to make sure that our code is going to work as expected.

02:55.250 --> 02:59.180
So now what we're going to do we're going to execute the specific test case.

02:59.180 --> 03:04.640
So the specific test case is going to make sure it's going to call this function and then return the

03:04.640 --> 03:05.840
value as an array.

03:06.230 --> 03:06.560
There we go.

03:06.590 --> 03:08.430
We got the response as is an array.

03:08.430 --> 03:11.070
And our assertion was also successful.

03:11.070 --> 03:15.390
So in this case, another thing that you want to see if you want to see what is actually being returned.

03:15.390 --> 03:18.150
So you can actually add a short over here.

03:18.150 --> 03:21.510
And then in this episode, what we can do is we can actually print the body.

03:21.510 --> 03:30.180
So in this case we can say response body is and then we can provide plus HTTP response dot body.

03:30.180 --> 03:35.520
So this can print the whole body in the console so that you can see what's returned from this specific

03:35.520 --> 03:36.330
endpoint.

03:37.500 --> 03:38.940
Let's execute this test case.

03:38.970 --> 03:39.600
There you go.

03:39.600 --> 03:43.350
So this specific test case is printed this whole JSON array.

03:43.380 --> 03:47.190
So basically JSON array being parsed as a string.

03:47.190 --> 03:48.420
And that's what this one is.

03:48.420 --> 03:53.370
And then this string gets converted into a list of movies using this specific code.

03:53.400 --> 03:57.120
I hope you all have a pretty good idea about how to build an HTTP client.

03:57.120 --> 04:02.100
That's going to be dealing with an array of elements, and using the object mapper, we were able to

04:02.100 --> 04:06.150
convert that array of elements into a collection of elements.

04:06.150 --> 04:08.160
In this case, that element is a movie.

04:08.160 --> 04:09.600
This marks the end of this lecture.

04:09.600 --> 04:10.770
Thank you for watching.
