‫We created the API or the service interface.
‫Now let's move to the last part, which is the retrofit.
‫And since we are using retrofit for network calls, let's create a class that provides us the instance
‫of the retrofit inside the service API package.
‫I'll create a new Java class and I'll name it as retrofit instance.
‫The retrofit library is used for making Http requests to web services or APIs.
‫The retrofit instance class is a crucial component of retrofit that acts as a central configuration
‫point for defining how Http requests and responses should be handled.
‫It provides settings like base URL, converters and other configurations necessary for making API requests.
‫I'll start by creating an instance from retrofit private static retrofit equal to null.
‫Initialize it as null.
‫Then I'll create a private static string base URL equal.
‫And here I need to specify the base URL.
‫We specified this part in the API service interface.
‫We're going to specify this base URL in the retrofit instance because this is not changeable.
‫Here you specify it.
‫Https api the movie db.org/3 slash.
‫Don't miss this slash.
‫Then I'll create a method public static named as get service method and it's returning type is of type
‫movie API service.
‫This method will provide us with a movie API service.
‫Let's start checking if this instance from retrofit equals to Null.
‫Then what we're going to make.
‫We're going to initialize retrofit and create a new one.
‫So retrofit equals to new retrofit dot builder.
‫And I'll use base URL here.
‫I specify this base URL.
‫This method sets the base URL for all relative URL paths in your API service interfaces.
‫All endpoints defined in the service interfaces will be relative to this base URL.
‫So the base URL defines the root URL for the API you are interacting with or relative.
‫Your URLs specified in your API service interface will be appended to this base URL to form the complete
‫end point URL.
‫Think about you start with this base URL, then the service interface will add the movie Popular End
‫Point and then it will add the query parameter API key and its past value.
‫Think about this is the job of retrofit.
‫Then add converter factory and here I'm using Json converter factory dot create.
‫This method specifies the converter factory to use for serializing and deserializing Json data.
‫In this example, Json converter factory is used to convert Json data into Java or Kotlin objects and
‫vice versa.
‫Retrofit supports other converter factories like Mochi, XML and more.
‫But in our example we're going to use and we use the Json converter for serialization and deserialization
‫and we talked about serialization and deserialization.
‫The last step is to use the build method.
‫Finally, you call build to a build method to create the retrofit instance.
‫Again, the converter factory determines how the data is converted between Json or other data formats
‫and Java or Kotlin objects.
‫After creating a retrofit instance, you can use it to create instances of your API service interfaces.
‫These service interfaces allow you to define and execute API requests.
‫So here we have this, and outside this if statement we need to return, return, retrofit, dot, create.
‫And here I need to create a movie API service to return it in the return statement.
‫So movie API service dot class.
‫So when you create a retrofit, you need to pass a service interface that define and describe the API
‫endpoints and their request or response formats.