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

A lightweight, modular, and generic Flutter networking library that acts as a unified communication layer between your app and remote APIs. Built on top of Dio and inspired by clean architecture princ [...]

# 🔗 lynk_io

A scalable and reusable API communication layer built with Dio for Flutter apps. 
Designed to simplify API calls, error handling, and 
dependency setup, following Clean Architecture and modular design.

---

## 🚀 Features

- Generic GET, POST, PUT, DELETE support  
- Clean separation of concerns using SOLID principles  
- Global error handling with proper exceptions  
- Simple logging with pluggable logger  
- Plug-and-play dependency injection via `get_it`  
- Supports `.env` based API URL configuration (cross-platform)  
- Easily extensible for token/auth-based flows  

---

## 📦 Installation

Add this to your `pubspec.yaml`:

```yaml
dependencies:
  lynk_io: ^1.0.0
  flutter_dotenv: ^5.1.0

🧱 Environment Setup #

To dynamically manage environments like dev, staging, and production:

  1. Create a .env file at the root of your Flutter app:
API_BASE_URL=https://jsonplaceholder.typicode.com
  1. Register the .env file in your pubspec.yaml:
flutter:
  assets:
    - .env
  1. Load the environment and set up dependencies before runApp():
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:lynk_io/lynk_io.dart';

void main() async {
  await dotenv.load();
  final baseUrl = dotenv.env['API_BASE_URL'] ?? '';
  setupDependencies(baseUrl: baseUrl);
  runApp(MyApp());
}

📦 Example API Usage #

Define a model class in your app layer:

class User {
  final int id;
  final String name;

  User({required this.id, required this.name});

  factory User.fromJson(Map<String, dynamic> json) =>
      User(id: json['id'], name: json['name']);
}

Fetch data using the reusable client:

final api = locator<ApiClient>();

final result = await api.get<User>(
  endpoint: '/users/1',
  fromJson: User.fromJson,
);

if (result.isSuccess) {
  AppLogger.log("User: ${result.data!.name}");
} else {
  AppLogger.error("Error: ${result.error!.message}");
}

📤 POST Request Example #

Sending a new user with POST:

final api = locator<ApiClient>();

final result = await api.post<User>(
  endpoint: '/users',
  body: {
    'name': 'John Doe',
    'email': 'john@example.com',
  },
  fromJson: User.fromJson,
);

if (result.isSuccess) {
  AppLogger.log("Created User: ${result.data!.name}");
} else {
  AppLogger.error("Error: ${result.error!.message}");
}

🔄 Other Supported Methods #

The package provides clean wrappers for all common REST methods:

GET<T>() #

api.get<T>(
  endpoint: '/items',
  fromJson: T.fromJson,
);

POST<T>() #

api.post<T>(
  endpoint: '/items',
  body: {...},
  fromJson: T.fromJson,
);

PUT<T>() #

api.put<T>(
  endpoint: '/items/1',
  body: {...},
  fromJson: T.fromJson,
);

DELETE<T>() #

api.delete<T>(
  endpoint: '/items/1',
  fromJson: T.fromJson,
);

These methods automatically handle:

  • JSON serialization with fromJson
  • Standardized ApiResponse<T> result
  • Error parsing into ApiError
  • Logging of request/response lifecycle

👨‍💻 Author #

Built and maintained with ❤️ by Siva G.

6
likes
0
points
40
downloads

Publisher

unverified uploader

Weekly Downloads

A lightweight, modular, and generic Flutter networking library that acts as a unified communication layer between your app and remote APIs. Built on top of Dio and inspired by clean architecture principles, lynk_io helps you abstract boilerplate, enforce response types, and centralize network error handling — all with minimal setup.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

connectivity_plus, dio, flutter, get_it, logger, meta

More

Packages that depend on lynk_io