api_request_handler 0.0.2 copy "api_request_handler: ^0.0.2" to clipboard
api_request_handler: ^0.0.2 copied to clipboard

A package for handling API requests with Dio with cache functionality and auto cancel duplicate requests.

API Service #

A lightweight and efficient Dart/Flutter package for handling API requests with optional response caching. Ideal for apps that need consistent, streamlined API access with performance optimization via local cache storage.

✨ Features #

  • Simple API request handling using Dio
  • Built-in request caching support
  • Automatic duplicate request cancellation
  • Support for GET, POST, PUT, DELETE, and other HTTP methods
  • Easily pluggable into any Flutter project
  • Customizable cache expiry
  • Support for multiple API clients (different base URLs per service)
  • Third-party API request support with isolated base logic

πŸš€ Getting started #

Prerequisites #

  • Flutter 3.10+
  • Add api_request_handler to your pubspec.yaml:
dependencies:
  api_request_handler:
    path: ../path_to/api_request_handler

Initialization #

ApiService.initialize(
  baseUrl: 'https://api.example.com',
  enableLogging: true,
  cacheEnabled: true,
);
// For multiple clients
await ApiService.initializeMultipleClients(
  baseUrls: {
    'consumer': 'https://consumer.example.com',
    'cas': 'https://cas.example.com',
  },
  globalHeaders: {
    'Authorization': 'Bearer token',
  },
  interceptors: [TokenInterceptor()],
);

πŸ“¦ Usage #

// Using a named client
final response = await ApiRequest.request(
  endpoint: '/users',
  method: 'GET',
  clientName: 'consumer',
);

// Using a third-party base URL
final thirdPartyResponse = await ApiRequest.request(
  endpoint: '/third-party-endpoint',
  method: 'POST',
  data: {'key': 'value'},
  isThirdParty: true,
  thirdPartyBaseUrl: 'https://thirdparty.com',
);

πŸ“ Example #

See the /example directory for a working Flutter integration demo.

πŸ“š Additional information #

  • This package uses Hive for caching (can be extended to other solutions).
  • Issues and contributions are welcome.
  • For suggestions or help, reach out to the package maintainer.
  • Now supports multiple clients and third-party base URLs.
4
likes
0
points
51
downloads

Publisher

verified publisherinnovationnxt.com

Weekly Downloads

A package for handling API requests with Dio with cache functionality and auto cancel duplicate requests.

License

unknown (license)

Dependencies

dio, flutter, hive, hive_flutter, path_provider

More

Packages that depend on api_request_handler