network_cool_client

A robust Dart package for efficient network request handling, session management, real-time network state tracking, and seamless error handling for modern applications.

Pub Version Pub Likes Pub Points Pub Downloads Dart SDK Version License codecov


โœจ Features

  • ๐Ÿ” Session-based client with auto token renewal and error handling
  • ๐ŸŒ Observes and notifies about network states (offline, maintenance, etc.)
  • ๐Ÿงฉ Extensible and easy to integrate with existing architectures
  • ๐Ÿงช Built-in testing and override-friendly design

๐Ÿš€ Installation

Add the package to your pubspec.yaml:

dependencies:
  network_cool_client: ^1.0.0

Then run:

dart pub get

๐Ÿ“† Usage

Basic usage

final client = NccClient(
  id: 'ncc-client',
  client: http.Client(),
);

final response = await client.get(Uri.parse('https://api.example.com/data'));

Session-based usage

final client = SessionClient(
  id: 'session-client',
  client: http.Client(),
);

final response = await client.get(
  Uri.parse('https://api.example.com/secure-data'),
);

You can customize token renewal, header logic, and handle session expiration seamlessly.


๐Ÿ“š API Reference

Check the full API reference on pub.dev โ†’ network_cool_client.


๐Ÿ’ก Examples

Creation of Custom Session Client

final class MySessionClient extends SessionClient {
  MySessionClient({required this.sessionTokenStorage, required this.renewSessionRepository})
      : super(
          id: 'my-session-client',
          client: Client(),
        );

    final LocalStorageOfSessionToken sessionTokenStorage;
    final RenewSessionRepository renewSessionRepository;

  @override
  Future<String?> getBearerToken() async {
    //Obtain the token from the datasource where you store on the login request
    final token = await sessionTokenStorage.call();
    return token;
  }

  @override
  Future<bool> renewSession() async {
    //Renew session as your application need
    final renew = await renewSessionRepository.call();
    return renew.isValid;
  }
}

You can find usage examples in the example/ folder.


๐Ÿค Contributing

Contributions are welcome!

  • Open issues for bugs or feature requests
  • Fork the repo and submit a PR
  • Run dart format and dart test before submitting

๐Ÿงช Testing

To run tests and see code coverage:

dart test

๐Ÿ“„ License

MIT ยฉ 2025 Coolosos

Libraries

ncc