igot_http_service_helper 0.5.0 copy "igot_http_service_helper: ^0.5.0" to clipboard
igot_http_service_helper: ^0.5.0 copied to clipboard

This package contains a set of high-level functions and classes that make it easy to consume HTTP resources. It's multi-platform (mobile, desktop, and browser) and supports multiple implementations wi [...]

igot_http_service_helper #

A Flutter package that provides a high-level HTTP service layer built on top of Dio. It supports TTL-based caching (powered by Hive), request deduplication, and configurable timeouts — designed for use in the iGOT Karmayogi project.

Migration note: As of v0.5.0 this package has migrated its underlying HTTP client from package:http to dio. The public HttpService API is unchanged; response objects are now dio.Response<dynamic> instead of http.Response.


Features #

HTTP Methods #

GET · POST · PUT · PATCH · DELETE · UPLOAD (multipart)

TTL-based Caching (Hive) #

TTL value Behaviour
null Hits the API directly every time
provided Checks Hive cache first
— cached & within TTL Returns cached data
— cached & expired Calls API, refreshes cache, returns fresh data
— not in cache Calls API, stores result, returns response

Force Update #

Set forceUpdate: true to bypass the cache and always fetch fresh data, then update the cache with the new response.

Request Deduplication #

Concurrent identical requests are collapsed into a single in-flight network call.

Configurable Timeouts #

Call HttpService.configure(...) once at startup to override connectTimeout, receiveTimeout, and sendTimeout.


Getting Started #

Add the package to your pubspec.yaml:

dependencies:
  igot_http_service_helper:
    git:
      url: https://git.idc.tarento.com/igot/http_service

Note: dio is a transitive dependency — you do not need to add it separately unless you need to import Dio types (e.g. Response, ResponseType) directly in your own code.


Usage #

Import #

import 'package:igot_http_service_helper/services/http_service.dart';
import 'package:dio/dio.dart'; // only if you use Dio types directly

Optional one-time configuration #

HttpService.configure(
  connectTimeout: const Duration(seconds: 10),
  receiveTimeout: const Duration(seconds: 30),
  sendTimeout:    const Duration(seconds: 15),
);

GET request (with caching) #

Response response = await HttpService.get(
  apiUri: Uri.parse('https://api.example.com/posts'),
  ttl: const Duration(hours: 1),
);

// response.data is already decoded (Map / List / String)
print(response.data);

POST request #

Response response = await HttpService.post(
  apiUri: Uri.parse('https://api.example.com/posts'),
  body: {'title': 'Hello', 'userId': 1},
  headers: {'Authorization': 'Bearer <token>'},
);

File upload (multipart) #

Response response = await HttpService.upload(
  apiUri: Uri.parse('https://api.example.com/upload'),
  filePath: '/path/to/file.pdf',
  fieldName: 'file',
  additionalFields: {'category': 'documents'},
);

Cache utilities #

// View cache statistics
Map<String, int> stats = await HttpService.getCacheStats();

// Remove only expired entries
await HttpService.clearExpiredCache();

// Wipe the entire cache
await HttpService.deleteAllCacheData();

Response Handling #

All methods return dio.Response<dynamic>. Access the body via response.data:

Response response = await HttpService.get(apiUri: Uri.parse('...'));

// If the server returns JSON, Dio decodes it automatically:
final data = response.data as Map<String, dynamic>;

// Check the HTTP status code:
if (response.statusCode == 200) { ... }

On network / HTTP errors, HttpService catches DioException internally and returns a structured error response rather than throwing, so callers can check the status code without a try/catch.


Configuration Details #

Tool Version
Flutter 3.35.7 (channel stable)
Dart 3.9.2
Dio ^5.9.1
Hive Flutter ^1.1.0
DevTools 2.48.0
0
likes
0
points
305
downloads

Publisher

unverified uploader

Weekly Downloads

This package contains a set of high-level functions and classes that make it easy to consume HTTP resources. It's multi-platform (mobile, desktop, and browser) and supports multiple implementations with DATA Base support with respect to given TTL.

Homepage

License

unknown (license)

Dependencies

crypto, dio, flutter, hive, hive_flutter, path

More

Packages that depend on igot_http_service_helper