bond_network 0.0.8 copy "bond_network: ^0.0.8" to clipboard
bond_network: ^0.0.8 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
0
points
10
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

License

unknown (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