Hi everyone.
Welcome back.
In this lecture we will learn about how to build the Rest client for the API that returns all the movies.
Right?
Which means an API that's going to return an array actually.
So in this case let's copy this one over here and then go to the browser.
So in the browser if you paste this URL.
So this is going to give you an array of response.
In this case as you can see it starts with an array.
And then it has this ten movies.
And then it ends with an array element okay.
So now what we are going to do.
We are going to write the code that's going to return a collection of movies.
So so far our client that we had built returned a single movie.
Now we are going to write a client that's going to return a list of movies.
So in this case let's go ahead and create a new function.
But the code logic is going to be pretty much the same.
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
okay.
It's not going to be Get movie by ID it's going to be get all movies.
And then in the place of movie by ID URL, we will pass the all movies Movie's URL.
In this case, let's pass the all movie's URL over here.
So when we get the response from this client, what we are going to get is an array of movies, right?
So that's going to be part of the HTTP response tool.
And then in the place of body, that whole HTTP array element is going to be present.
So in the case of parsing this from a single movie to an array, what we have to do is there is an way
in object mapper you can actually apply the array deserialization.
So in this case what we can do is there is a class name new type reference.
And then all you got to do is provide this one.
So this should automatically apply that logic for you.
I don't think we even need this one actually.
Let's go ahead and remove it.
So all you got to do is do this.
This should take care of automatically converting that string array into a array of movies.
So in this case let's go ahead and remove this one.
And then this is going to be a list of movie.
So in this case it's going to be list of movie.
So let's go ahead and import the necessary classes.
There you go.
There we go.
So this specific logic is going to take care of automatically Dramatically converting a string array
to an array of movies, or in this case, it's going to be a collection of movies.
So in this case, what we can do, we can write a test very similar to what we did over here.
Put it over here.
But instead of get movie by ID, we're going to call get all movies by ID, get all movies by ID and
get all movies by ID over here.
So in this case, we can change our assertions a little bit.
So what we can do is we know this list is going to hold ten elements.
So what we can do so we can do assert.
So we can name this one as movies list.
And we can have movies list dot size equal to equal to ten.
Okay we can do that.
And then we can actually complete our assertions.
This is good enough for to make sure that our code is going to work as expected.
So now what we're going to do we're going to execute the specific test case.
So the specific test case is going to make sure it's going to call this function and then return the
value as an array.
There we go.
We got the response as is an array.
And our assertion was also successful.
So in this case, another thing that you want to see if you want to see what is actually being returned.
So you can actually add a short over here.
And then in this episode, what we can do is we can actually print the body.
So in this case we can say response body is and then we can provide plus HTTP response dot body.
So this can print the whole body in the console so that you can see what's returned from this specific
endpoint.
Let's execute this test case.
There you go.
So this specific test case is printed this whole JSON array.
So basically JSON array being parsed as a string.
And that's what this one is.
And then this string gets converted into a list of movies using this specific code.
I hope you all have a pretty good idea about how to build an HTTP client.
That's going to be dealing with an array of elements, and using the object mapper, we were able to
convert that array of elements into a collection of elements.
In this case, that element is a movie.
This marks the end of this lecture.
Thank you for watching.