Networking
The two classes
Section titled “The two classes”ApiClient(lib/core/network/api_client.dart) — configures thediosingleton: the HTTP/2 adapter,Authorization: Bearer <token>read from the globalcurrent_userValueNotifier, and aUser-Agentheader viaua_client_hints. It also hosts the disk cache interceptor used by the cache-first boot.DioApiProvider(lib/core/network/dio_api_provider.dart) — the abstract base every datasource HTTP call goes through. It owns noDioof its own; it reads theApiClient.instancesingleton.
Never construct a Dio() in a datasource — that was once the single most
expensive line in the app (the network layer deep
dive tells that story).
Conventions applied automatically
Section titled “Conventions applied automatically”Every backend call made through DioApiProvider gets:
- Query params:
country=<code>andplatform=mobileeverywhere; GETs also sendlanguage=<en|bn>. - Headers:
Accept/Content-Type: application/json, theua_client_hintsUser-Agent, andAuthorization: Bearer <token>when logged in. - Timeouts: GET 20s · POST 30s · PUT/DELETE 60s.
- Caching: static GETs use
dio_cache_interceptorwith 7-day max-stale; the cache is bypassed on 401/403.
| Base | Purpose |
|---|---|
api-static.chorki.com |
Catalog/content (GET, CDN-cached) |
api-dynamic.chorki.com |
Auth + user data & writes |
ipinfo.chorki.com |
Geo / VPN detection (sets country) |
analytics.chorki.com |
Matomo |
kms.chorki.net |
The AES key server — see Playback |
video.chorkicdn.com |
HLS playlists / segments |
With --dart-define=USE_STAGING=true the app switches to the
*-porikkhamulok.chorki.net staging hosts and the Turnstile test site key.
The full endpoint catalogue (64 requests, with the Postman collection) is in
the API reference.
Adding a call
Section titled “Adding a call”- Model in
lib/data/models/— hand-writtenfromJson/toEntity(). - Method on the datasource in
lib/data/datasources/, extendingDioApiProvider. - Repository contract in
lib/domain/repositories/, implementation inlib/data/repositories/returningEither<Failure, T>. - Thin use case in
lib/domain/usecases/if the logic is worth naming. - Register everything in
lib/injection_container.dart.