1
Declare the Retrofit interface
- This defines an interface for making API calls using Retrofit.
- @GET(“places/”) specifies that this method sends a GET request to the “places/” endpoint.
@QueryMap parameters: Map<String, String>allows passing multiple query parameters dynamically.- The response is wrapped in
Response<PlaceAPIResponse>, meaning it will be an HTTP response containingPlaceAPIResponse.
2
Create the Retrofit instance
- Retrofit.Builder() initializes the Retrofit instance.
- .baseUrl(“https://api.baato.io/api/v1/”) sets the base URL for API calls.
- .addConverterFactory(GsonConverterFactory.create()) allows automatic JSON parsing.
- retrofit.create(BaatoAPI::class.java) generates an implementation of the BaatoAPI interface.
suspend fun getPlaceDetails(params: Map<String, String>)is a suspending function that calls the API.- It fetches a response and extracts the body (PlaceAPIResponse).
- If the response is null, an exception is thrown.
3
Model the response envelope
- This defines the response structure:
- timestamp: When the API responded.
- status: HTTP status code.
- message: API message.
- data: A list of Place objects.
4
Model a place
- Represents a location retrieved from the API.
- Key properties:
- score: Ideally should be Double instead of Any.
- centroid: Represents the center of the place (LatLon).
- geometry: Represents spatial data (Geometry).
5
Make Place parcelable
- Implements Parcelable to pass Place objects between activities/fragments.
- Uses Parcel to serialize and deserialize the data.
6
Model the geometry
- Represents the spatial structure of a place.
- type: Type of geometry (e.g., Point, Polygon).
coordinates: Should ideally be aList<Double>instead ofAny.
7
Model the coordinate pair
- Represents latitude and longitude of a place.
8
Make the call
- queryMaps holds the API query parameters (key and placeId).
- apiService.getPlaceDetails(queryMaps) fetches the place details.