Skip to main content

sinew_network 1.1.0 copy "sinew_network: ^1.1.0" to clipboard
sinew_network: ^1.1.0 copied to clipboard

SinewHttp (Dio), the auth layer, processApiCall, retry, polling and NetworkChecker.

sinew_network #

pub package License Docs

SinewHttp (Dio): the auth layer, processApiCall, retry, polling and NetworkChecker.

An HTTP client that handles what every app rewrites: attaching the token only to your backend, refreshing it once for any number of concurrent 401s, mapping responses to typed failures, and retrying and polling with backoff. Use the preset, or add only the interceptors you need to your own Dio.

Features #

  • SinewHttp.dio: a Dio with timeouts, headers, auth, error bodies and logging from one SinewConfig
  • SinewAuthInterceptor: the token goes only to baseUrl's host, outside the anonymous paths, with a single-flight refresh through TokenSource and SessionTokenSource
  • processApiCall and processOptionalApiCall: map an Envelope to a Result and every status to a typed SinewException
  • retryWithBackoff and poll, NetworkChecker, pinCertificateAuthorities, and SinewHttpHooks for the devtools

Getting started #

flutter pub add sinew_network

Usage #

final config = SinewConfig(
  baseUrl: 'https://api.example.com/v1',
  locale: () => 'en',
  anonymousPaths: {'/auth/login'},
);
final dio = SinewHttp.dio(config, tokenSource);

// In a repository: any failure becomes a typed SinewException.
Future<Result<Order>> cancel(String id) =>
    processApiCall('ORD', 'CANCEL', () => api.cancel(id));

API classes use paths relative to baseUrl (get('orders')), since a leading / would replace its own path. On sign-out, call SinewHttp.resetAuth(dio) and tokenSource.clear().

Sinew is one architecture for Flutter and Kotlin, released as a set of packages at one version.

Documentation #

License #

Apache 2.0, see LICENSE.

0
likes
160
points
306
downloads

Documentation

Documentation
API reference

Publisher

verified publishersrctool.com

Weekly Downloads

SinewHttp (Dio), the auth layer, processApiCall, retry, polling and NetworkChecker.

Repository (GitHub)
View/report issues
Contributing

Topics

#http #dio #networking #authentication

License

Apache-2.0 (license)

Dependencies

connectivity_plus, dio, flutter, sinew_exception, sinew_models

More

Packages that depend on sinew_network