Services

Services are focused classes designed to interact with web API endpoints. As a good design pattern a service should:

  • Only interact with a single domain
  • Only provide features from the domain which are relevant to the theme of the service. Eg. A user service should be focused on methods that support such; adding order related data would make for poor encapsulation.
frontier mobile add service <service-name>

Example

frontier mobile add service auth

Output File

services/auth.service.tsx

Technical

Each generated service is contained within the sub-folder services directory. The directory contains a file for each service that has been created:

  • [service-name].service.tsx: The file will contain a related grouping of http functions.
  • While each generated service resides in its own file and class, all services extend a predefined BaseService class in order to provide centralized functionality.
  • Each service is able to specify a unique web API endpoint with which to interact - or none at all for services providing local functionality (Eg. wrapper storage mechanism over AsyncStorage).