ApiConfigService
TheApiConfigService provides centralized configuration management for API endpoints and feature flags. It reads configuration from Angular environment files and exposes them through a type-safe interface.
Overview
This core service acts as a single source of truth for API configuration throughout the application. It encapsulates environment-specific settings and provides a clean interface for accessing the backend API base URL.The service reads from Angular’s
environment object, which switches between environment.ts (development) and environment.production.ts (production) during the build process.Service API
Provided In
Public Properties
Returns the base URL for all API requestsExample values:
- Development:
http://localhost:8080/api - Production:
https://api.airtracker.example.com
Configuration Interface
ApiConfig interface
Configuration Properties
Base URL for backend API requests
Feature flags for enabling/disabling application features
Indicates whether the app is running in production mode
Usage Examples
Accessing API Base URL
FlightsApiService usage
Environment Configuration
The service reads from environment files:environment.development.ts
environment.production.ts
Implementation Details
The service stores a private readonly configuration object initialized from the environment:Internal structure
Real-World Usage
FlightsApiService
The API service usesApiConfigService to construct endpoint URLs:
Configuration Management
Development Environment
- Points to local backend server
- Enables development-specific debugging
- Features may be disabled for testing
Production Environment
- Points to production API
- Optimized builds with AOT compilation
- All features enabled
Benefits
- Centralized configuration: Single place to manage API settings
- Type safety:
ApiConfiginterface prevents configuration errors - Environment awareness: Automatically switches between dev/prod configs
- Easy mocking: Can be easily replaced in tests
- Extensible: Feature flags allow gradual feature rollout
Future Enhancements
Thefeatures object supports future functionality:
| Feature | Status | Description |
|---|---|---|
enableFavorites | Planned | Save and manage favorite flights |
enableStats | Planned | View flight statistics and analytics |
Related
- FlightsApiService - Primary consumer of this service
- Architecture: API Integration - How API configuration fits into the architecture
Source
~/workspace/source/src/app/core/services/api-config.service.ts