Creating an API data service
Using BaseHttpService
as a foundation that abstracts away the HTTP request details, we can now begin to create services that leverage it to get responses back from the API in the form of domain-specific models. Specifically, we will create a data service that can be used by the ViewModels to get the TripLogEntry
objects from the backend service.
We will start off by defining an interface for the data service that can be injected into the ViewModels, ensuring that there is no strict dependency on the API, or the logic that communicates with it, continuing the pattern we put in place in Chapter 4, Platform-Specific Services and Dependency Injection. To create a data service for the TripLog API, perform the following steps:
- Create a new interface named
ITripLogDataService
in theServices
folder of the core library:public interface ITripLogDataService { }
- Update the
ITripLogDataService
interface with methods to get and add newTripLogEntry
objects...