‫Welcome back.
‫In the previous videos we created the data classes, result and movie.
‫In this video we'll create the API or the service interface for retrofit.
‫We need to create an interface to define our different methods that will be used for network transactions.
‫Let's create a new package and I'm creating packages just for organizing my codes.
‫I'll create a new package, I'll name it as service API, and here inside it I'll create a new interface
‫named as movie API service.
‫In retrofit The service interface is a key component that defines the structure and behavior of the
‫API requests.
‫It acts as a bridge between your Android app and the remote API.
‫And as mentioned before, we have base URL, end point, start of the query and the query parameters.
‫In this service API interface, we define the endpoints and the query parameters.
‫I'll start with get annotation, get in order to get data from the server post is to post and upload
‫data to the server.
‫Here we need in our application just to display the list of movies popular movies.
‫Here you specify your end point.
‫I'll start by the end point of link.
‫Is movie slash popular?
‫I'll specify movie slash popular.
‫So here I'm specifying the Http request method, which is get.
‫And here is the relative URL path to a specific API point endpoint, which is the popular movies.
‫Then I'll create a call and get the result.
‫And here I'm passing the type parameter result that we have created before get popular movies.
‫And here I need to specify the query.
‫But first, what is call retrofit uses?
‫Call class to represent a network request and its response response type should be replaced with the
‫actual data model class that represents the expected response from the API.
‫So if you go back to this response, this is the whole response.
‫We have included this response into a model class called result.
‫So if we open the model result, we're going to get the response like this.
‫Then I'm going to create a list of movie data class to get this response array.
‫So this is a nested model class and this is the whole response.
‫The whole response is inside the result class.
‫So here I'll specify the result that represents the expected response from the API.
‫I created this method Get popular movies that returns a call of type.
‫We finished this end point here.
‫We need to specify the query parameters and as mentioned before, Tmdb will not give you any response
‫until you specify the API key in every request you make.
‫I should start a query parameter and specify the API key to do that in retrofit.
‫We'll start by adding at query annotation and here I'll specify exactly the name of the query parameter,
‫which is API.
‫Underscore key.
‫Back to the link.
‫You can see it API key here.
‫So I should mention it exactly here.
‫And the value is type string.
‫I name it as API key.
‫Every time I request the popular movies, I should mention an API key and passed as a parameter here.