‫Hello, my friends, and welcome back.
‫In this video, we will continue implementing retrofit in our application.
‫In the previous videos we created the data classes, the Pojo one for the the Json objects and one for
‫the Json array.
‫So we created two modal classes or two classes that represents the data classes.
‫Now we are going to create the API service interface.
‫We need to create an interface to define our different methods that will be used for network transactions.
‫Back to our website, the Json placeholder dot type code.com, but there is a slash albums.
‫This is the link that we're going to use.
‫But this is if I go back to here, the placeholder, I can scroll down and I can fetch for example posts.
‫So I will open in a new tab.
‫You can see that this is a new Json file.
‫But the thing here that this is a the same link as this, but the difference is the post slash post
‫and the difference is slash albums.
‫So this is called a base URL and this is called an end point.
‫So you can see end point posts and point albums and point photos.
‫So if I open it, you can see photos here.
‫So every end point will result in a different Json file.
‫So.
‫This is the link.
‫This is called base URL.
‫We will include this read in the retrofit instance and the endpoint.
‫We should include this endpoint in the service interface method.
‫So back to our Android studio project, Create new Kotlin class Select interface, and now I will name
‫it as album service album.
‫Service.
‫I prefer, including the keywords in order to understand that this is the interface that serves as a
‫service in the retrofit implementation.
‫So this is the second step which is creating the API or the service classes for the.
‫Retrofit.
‫Let's start with a suspend function.
‫You can create a normal function like this, but since I'm going to use the in this project and include
‫the Coroutines in order to practice them well and get data in background, I'm going to use the coroutines.
‫So get albums.
‫This is the method and here I will return a response.
‫So in retrofit all the responses are included inside the response object and what is the type of the
‫response it's of type.
‫You can go back to the.
‫Link here.
‫The first top level thing in this Json file is an array.
‫So I should.
‫Include here type T class that represent this array.
‫I have created, as you know, two classes, one for fetching the upper and the outer array and one
‫for fetching the inner objects.
‫In retrofit.
‫We need to fetch the outer response.
‫So the outer response is of type albums because it's an array list of album items.
‫It's an array of albums.
‫You can see an array of albums.
‫The first album, this is the second album, so it's an array of albums.
‫I'm telling that this response should return for me and store them inside an albums type.
‫And as I told you, since I am getting I am fetching the data from this website.
‫So as I told you and as we lectured before about get and post I, I'm not going to post data to the
‫server.
‫I'm going to get the data from the server, getting the albums from the server.
‫So I'm going to use the get method from the Http or the retrofit.
‫Package.
‫Here I am passing the value of the endpoint so you can see why I was lecturing about the.
‫Uh, the endpoint and the base URLs.
‫I am specifying here the end points.
‫So always use the end points in the interface and here.
‫You should specify.
‫The end points of the Earl.
‫Okay in this interface.
‫So the album Interface Service or the APIs API service interface you should use and you should specify
‫the endpoints of the URL.
‫So since I am going to use the albums.
‫The albums.
‫End point.
‫So I will copy it exactly as it because it's of type case sensitive.
‫Okay.
‫I will paste it here.
‫And here we go.
‫I'm telling I need to fetch the endpoint called albums from the base URL.
‫Later on we will specify the base URL in the retrofit instance.