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

retracted

Network Kit is a library that provides a set of tools to work with network requests.

NetKit #

NetKit is a Dart package designed to handle HTTP requests and responses efficiently.

netkit

Contents #

Inspiration #

NetKit was inspired by the popular Vexana package by VB10

Features #

  • Supports various HTTP methods (GET, POST, PUT, DELETE, PATCH)
  • Configurable base URLs for development and production
  • Logging of network requests and responses
  • Error handling and response validation
  • Parsing responses into models or lists of models or void using INetKitModel

Getting started #

Initialization #

Initialize the NetKitManager with the parameters:

import 'package:netkit/netkit.dart';

final netKitManager = NetKitManager(
  baseUrl: 'https://api.<URL>.com',
  devBaseUrl: 'https://dev.<URL>.com',
  loggerEnabled: true,
  testMode: true,
  errorStatusCodeKey: 'status',
  errorMessageKey: 'description',
);

Sending requests #

Request a Single Model

Future<RandomUserModel> getRandomUser() {
  try {
    return netKitManager.requestModel<RandomUserModel>(
      path: '/api',
      method: RequestMethod.get,
      model: const RandomUserModel(),
    );
  }
  /// Catch the ApiException and handle it
  on ApiException catch (e) {
    /// Handle the error: example is to throw the error
    throw Exception(e.message);
  }
}

Request a List of Models

Future<List<ProductModel>> getProducts() async {
  try {
    return netKitManager.requestList<ProductModel>(
      path: '/products',
      method: RequestMethod.get,
      model: const ProductModel(),
    );
  }
  /// Catch the ApiException and handle it
  on ApiException catch (e) {
    /// Handle the error: example is to throw the error
    throw Exception(e.message);
  }
}

Send a void Request

Future<void> deleteProduct() async {
  try {
    return netKitManager.requestVoid<ProductModel>(
      path: '/products',
      method: RequestMethod.delete,
    );
  }
  /// Catch the ApiException and handle it
  on ApiException catch (e) {
    /// Handle the error: example is to throw the error
    throw Exception(e.message);
  }
}

Contributing #

Contributions are welcome! Please open an issue or submit a pull request.

License #

This project is licensed under the MIT License.

4
likes
0
pub points
47%
popularity

Publisher

verified publisherbehzod.dev

Network Kit is a library that provides a set of tools to work with network requests.

Repository (GitHub)
View/report issues

Topics

#network #network-manager #remote-data #dio

License

unknown (license)

Dependencies

dio

More

Packages that depend on net_kit