anynet 0.1.0-dev.1 copy "anynet: ^0.1.0-dev.1" to clipboard
anynet: ^0.1.0-dev.1 copied to clipboard

AnyNet is a Flutter networking layer (DEV) with get/post/put/delete helpers, retry, timeout, caching, offline support, logging, and unified error handling.

AnyNet πŸš€

Pub Version | License: MIT

  • Unified Networking for Flutter (DEV Preview)
  • Version: 0.1.0-dev.1
  • Status: Experimental / Developer Preview

✨ What is AnyNet? #

  • AnyNet is an experimental networking layer for Flutter that provides a clean, unified API inspired by http and dio, with built-in features that apps usually re-implement again and again.
  • It is designed to replace direct usage of http / dio in application code, while remaining flexible and adapter-driven internally.

⚠️ This is a DEV release. APIs may change based on feedback.

🎯 Why AnyNet? #

  • Using http or dio directly often leads to:
  • Repeated boilerplate
  • Inconsistent error handling
  • Manual retry logic
  • Scattered logging
  • Custom caching everywhere
  • AnyNet solves this by design.

βœ… Features (v0.1.0-dev.1) #

  • Core Networking
  • get / post / put / delete helpers
  • Base URL support
  • JSON ↔ Object mapping
  • Unified ApiResponse
  • Unified ApiError
  • Reliability
  • Automatic retry with exponential backoff
  • Timeout handling
  • Connectivity-aware requests
  • Cancelable requests

Architecture #

  • Interceptor system (like Dio)
  • Logging interceptor (built-in)
  • Pluggable adapters (IO-based for now)

Caching #

  • In-memory request caching
  • Cache-aware GET requests

❌ What’s NOT included (yet) #

  • Persistent cache (disk)
  • Multipart uploads
  • Auth refresh handling

Web adapter #

  • Advanced Dio parity
  • These will arrive after feedback.

πŸ“¦ Installation #

  • dependencies: anynet: ^0.1.0-dev.1

πŸš€ Quick Start #

1️⃣ Create a client

final client = AnyNetClient(
    baseUrl: 'https://jsonplaceholder.typicode.com',
    retryPolicy: const RetryPolicy(maxRetries: 2),
    cache: MemoryCache(),
    interceptors: [LoggingInterceptor()],
);

2️⃣ GET request

final response = await client.get<User>(
    '/users/1',
    mapper: (json) => User.fromJson(json),
);

if (response.isSuccess) {
    print(response.data);
}

3️⃣ POST request

final response = await client.post<User>(
    '/users',
    body: {
        'name': 'AnyNet User',
        'email': 'anynet@example.com',
    },
    mapper: (json) => User.fromJson(json),
);

4️⃣ PUT / DELETE

await client.put(
    '/users/1',
    body: {'name': 'Updated Name'},
);

await client.delete('/users/1');

πŸ”„ Unified Response Model #

class ApiResponse<T> {
    final T? data;
    final ApiError? error;
    final int? statusCode;
    
    bool get isSuccess => error == null;
}

❗ Unified Error Handling #

switch (response.error?.type) {
    case ApiErrorType.offline:
        print('No internet');
    case ApiErrorType.timeout:
        print('Request timed out');
    case ApiErrorType.network:
        print('Network error');
    default:
        print('Unknown error');
}

🧩 Interceptors #

  • Create interceptors just like Dio:

      class LoggingInterceptor extends AnyNetInterceptor {
          @override
          Future<ApiRequest> onRequest(ApiRequest request) async {
              print('β†’ ${request.method} ${request.url}');
              return request;
          }
        
          @override
          Future<ApiResponse> onResponse(ApiResponse response) async {
              print('← ${response.statusCode}');
              return response;
          }
        
          @override
          Future<ApiError> onError(ApiError error) async {
              print('βœ– ${error.message}');
              return error;
          }
      }
    

πŸ§ͺ Example App #

  • A full example is available in /example showing:
  • GET list (ListView)
  • POST / PUT / DELETE
  • Retry & backoff

Logging #

  • Offline simulation
  • Error β†’ UI mapping

🧠 Design Philosophy #

  • Simple for beginners
  • Powerful for advanced users
  • Minimal boilerplate
  • Predictable behavior
  • AnyNet is not about hiding networking β€” it’s about standardizing it.

πŸ›£ Roadmap #

  • Dio adapter
  • Persistent cache
  • Auth interceptors
  • Multipart uploads
  • Web support
  • Metrics & tracing

🀝 Contributing #

  • This is an early DEV release β€” feedback is extremely valuable.
  • Issues
  • Feature requests
  • API suggestions
  • All welcome πŸ™Œ

⭐ Final Note #

If you currently use http or dio directly in your app,AnyNet lets you stop worrying about networking infrastructure and focus on business logic. #

0
likes
150
points
37
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

AnyNet is a Flutter networking layer (DEV) with get/post/put/delete helpers, retry, timeout, caching, offline support, logging, and unified error handling.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on anynet