Skip to content

Networking

  • ApiClient (lib/core/network/api_client.dart) — configures the dio singleton: the HTTP/2 adapter, Authorization: Bearer <token> read from the global current_user ValueNotifier, and a User-Agent header via ua_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 no Dio of its own; it reads the ApiClient.instance singleton.

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).

Every backend call made through DioApiProvider gets:

  • Query params: country=<code> and platform=mobile everywhere; GETs also send language=<en|bn>.
  • Headers: Accept/Content-Type: application/json, the ua_client_hints User-Agent, and Authorization: Bearer <token> when logged in.
  • Timeouts: GET 20s · POST 30s · PUT/DELETE 60s.
  • Caching: static GETs use dio_cache_interceptor with 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.

  1. Model in lib/data/models/ — hand-written fromJson / toEntity().
  2. Method on the datasource in lib/data/datasources/, extending DioApiProvider.
  3. Repository contract in lib/domain/repositories/, implementation in lib/data/repositories/ returning Either<Failure, T>.
  4. Thin use case in lib/domain/usecases/ if the logic is worth naming.
  5. Register everything in lib/injection_container.dart.