API Integration
How the mobile app integrates with the backend API.
API Configuration
All API endpoints are configured in:
lib/config/api_config.dart
Making API Calls
GET Request
final response = await http.get(
Uri.parse(ApiConfig.getProviderEndpoint(providerId)),
headers: {'Content-Type': 'application/json'},
);
POST Request
final response = await http.post(
Uri.parse(ApiConfig.sendOtpEndpoint),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'phone': phoneNumber,
'role': role,
}),
);
PUT Request
final response = await http.put(
Uri.parse(ApiConfig.updateProfileEndpoint),
headers: {'Content-Type': 'application/json'},
body: jsonEncode(profileData),
);
Error Handling
try {
final response = await http.get(uri);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
return data;
} else {
final error = jsonDecode(response.body);
throw Exception(error['error'] ?? 'Request failed');
}
} catch (e) {
print('API Error: $e');
rethrow;
}
Response Format
Most API responses follow this format:
{
"success": true,
"data": {...},
"message": "Success message"
}
Authentication
Currently, the app uses phone-based authentication. API calls that require authentication typically don't use tokens, but session-based authentication may be added.
Rate Limiting
The app handles rate limiting responses:
if (response.statusCode == 429) {
final errorData = jsonDecode(response.body);
// Handle rate limit error
// Show nextAllowedAt to user
}
Services
API calls are organized into service classes:
ProviderService- Provider-related API callsServiceSeekerService- Service seeker API callsAuthService- Authentication API callsChatService- Messaging API calls
Each service handles specific domain logic and API interactions.