The third step is to create the retrofit provider, select new object, name it as Retrofit Provider.
Inside this object, we need to create a function that provides us with the directions service instance
function create direction service that returns a directions service instance.
This function takes a base URL as a string parameter.
Don't worry, we're going to clarify everything in this example.
Now return retrofit builder dot base url alt+.
Enter to import retrofit instance base url.
Pass the base URL parameter passed by the create directions service and add converter.
Factory JSON for converter factory dot create dot build function dot create direction service class.
This is what we've done and we talked about in the previous sections and in previous applications when
we worked with retrofit.
But don't worry, we're going to make a quick recap about it.
This object defines a utility object called retrofit Builder, and the retrofit provider that creates
and provides instances of retrofit service for directions related API calls.
The object declaration object retrofit provider.
This creates a singleton object.
Only one instance exists in the application.
No need to instantiate it.
You can call its functions directly via retrofit provider dot create directions service, for example,
or any function name.
Create directions service is a function taking a base URL string as a parameter.
Returning an implementation of directions service.
The retrofit builder starts building a retrofit instance.
Base URL sets the base URL for all API calls.
As I said to you, the base URL of the URL of the API is the constant part of the API call dot add converter
factory adds.
As the converter for JSON serialization and deserialization as we talked about.
Retrofit.
It needs a converter that uses.
That uses serialization and deserialization for converting JSON and JSON response to Kotlin objects
and vice versa.
Build finalizes and creates the retrofit instance.
Create a function.
Generates an implementation of direction service interface.
This is a clean way to centralize retrofit service creation.
The directions service is an interface defining API endpoints.
Decent is used for JSON conversion.
You could swap this for emoji or other converters, but as I said to you, JSON is the more professional
and it's fast.
The base URL is parameterized for flexibility.
Could point to different environments.
Okay, so this pattern is commonly used in Android application to abstract away retrofit setup and provide
easy access to API services.