Overview
App Courier uses Dio HTTP client for all API communications. The API client handles authentication, request/response interceptors, and error handling automatically.API Client Configuration
The main API client is located inlib/core/api/api_client.dart and provides a centralized HTTP client with built-in authentication.
Base Configuration
Configuration Parameters
The base URL for all API requests. Currently set to
https://api.eisegmi.facturador.esMaximum time to wait for connection establishment
Maximum time to wait for response after connection
Default headers sent with every request. Includes
Content-Type: application/jsonChanging the API Base URL
To use a different API endpoint:- Open
lib/core/api/api_client.dart - Modify the
baseUrlin theBaseOptions:
Authentication
The API client automatically handles Bearer token authentication using interceptors.Token Management
Authentication tokens are stored securely using SharedPreferences:How It Works
User Login
When a user logs in successfully, the authentication token is stored in SharedPreferences with the key
'token'.Automatic Injection
For every API request, the interceptor retrieves the token and adds it to the
Authorization header as Bearer {token}.Error Handling
The API client includes automatic error handling for common scenarios.401 Unauthorized Handler
When a 401 Unauthorized response is received, the stored token is automatically cleared. You should implement navigation to the login screen in this handler.
Status Code Validation
The client validates response status codes:API Methods
The ApiClient provides standard HTTP methods:GET Request
POST Request
PUT Request
DELETE Request
Using the API Client
Dependency Injection
Create a single instance and inject it where needed:With Provider
Advanced Configuration
Custom Headers
Add custom headers to specific requests:Timeout Customization
Override timeout for specific requests:Request Logging
Add logging interceptor for debugging:Troubleshooting
Connection Timeout Errors
Connection Timeout Errors
If you’re experiencing frequent timeout errors:
- Check your network connection
- Verify the API server is accessible
- Increase
connectTimeoutandreceiveTimeoutvalues - Check for firewall or proxy restrictions
401 Unauthorized
401 Unauthorized
CORS Issues
CORS Issues
CORS issues typically occur in web development:
- Configure your backend to allow requests from your domain
- Add appropriate CORS headers on the server
- Flutter mobile apps don’t face CORS restrictions
SSL Certificate Errors
SSL Certificate Errors
If you encounter SSL/TLS errors:
- Ensure the API server has a valid SSL certificate
- For development, you can bypass SSL (not recommended for production)
- Check device date/time settings
Next Steps
Environment Config
Learn about environment variables and build modes
Permissions
Configure required Android and iOS permissions