bond_network 0.0.11+9 copy "bond_network: ^0.0.11+9" to clipboard
bond_network: ^0.0.11+9 copied to clipboard

Network is a Bond package provides a convenient way to handle API response.

📘 Bond API Request – Simple Example #

This file demonstrates how to make basic API requests using the Bond API system. It includes examples for GET and POST requests with optional caching, body submission, and custom deserialization.


✅ GET Request with Caching #

final response = await GetBondApiRequest<MyModel>(dio, '/products')
  .factory((json) => MyModel.fromJson(json))
  .cache(
    duration: const Duration(minutes: 5),
    cacheKey: 'product-list',
    cachePolicy: CachePolicy.cacheElseNetwork,
  )
  .execute();

📨 POST Request with JSON Body #

final response = await BaseBondApiRequest<MyResponseModel>(dio, '/login', method: 'POST')
  .body({
    'email': 'user@example.com',
    'password': 'secret',
  })
  .header({'Accept-Language': 'en'})
  .factory((json) => MyResponseModel.fromJson(json))
  .errorFactory((json) => ApiError.fromJson(json))
  .execute();

💾 Caching Custom Values from Response #

final response = await BaseBondApiRequest<MyResponseModel>(dio, '/login', method: 'POST')
  .body({'email': 'me@example.com', 'password': 'password'})
  .factory((json) => MyResponseModel.fromJson(json))
  .cacheCustomKey('access_token', path: 'accessToken')
  .execute();

// Retrieve later:
final token = await Cache.get<String>('access_token');

🪪 Streaming with cacheThenNetwork #

final stream = GetBondApiRequest<MyModel>(dio, '/profile')
  .cache(
    duration: Duration(minutes: 10),
    cacheKey: 'profile-data',
    cachePolicy: CachePolicy.cacheThenNetwork,
  )
  .factory((json) => MyModel.fromJson(json))
  .streamExecute();

stream.listen((data) {
  print('Profile: \${data.name}');
});

🛠 Model Example #

class MyModel {
  final int id;
  final String name;

  MyModel({required this.id, required this.name});

  factory MyModel.fromJson(Map<String, dynamic> json) =>
      MyModel(id: json['id'], name: json['name']);
}
1
likes
140
points
68
downloads

Publisher

unverified uploader

Weekly Downloads

Network is a Bond package provides a convenient way to handle API response.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

bond_cache, bond_core, dio, equatable, faker, flutter, json_annotation, json_serializable, meta, package_info_plus

More

Packages that depend on bond_network