Overview
TheLocationsService is an Angular service that handles HTTP requests for location data. It provides methods to fetch states and cities with pagination and filtering capabilities.
Location: src/app/features/paginator/services/locations.service.ts
Methods
getStates()
Retrieves all available states from the API. Signature:StatesResponse
Example:
getCities()
Retrieves cities from the API with optional filtering and pagination. Signature:filters:CityFilters- Object containing filter criteriastate?:string- Filter by state codepageSize?:number- Number of items per pagepage?:number- Page number to retrieve
CitiesResponse
Example:
TypeScript Interfaces
CityFilters
StatesResponse
CitiesResponse
State
City
Pagination
API Endpoints
The service uses the base URL fromenvironment.apiUrl:
- GET
/states- Retrieves all states - GET
/cities?state={state}&page={page}&pageSize={pageSize}- Retrieves filtered cities
Implementation Details
- The service is provided in the root injector (
providedIn: 'root') - Uses Angular’s
HttpClientfor HTTP requests - Query parameters are built using
HttpParamsfor the cities endpoint - All optional filters are only added to the request if they have values
- Returns RxJS Observables for reactive data handling