Skip to content

coderspace_network is a lightweight, developer-friendly Flutter package for making REST API calls using Dio. It provides clean, generic request handling, consistent error management, and simple utilities like auto-list parsing—all with minimal code.

License

Notifications You must be signed in to change notification settings

coderspacedev/coderspace_network

Repository files navigation

coderspace_network

coderspace_network is a lightweight, developer-friendly Flutter package for making REST API calls using Dio. It provides clean, generic request handling, consistent error management, and simple utilities like auto-list parsing—all with minimal code.

📦 Installation

Add this to your pubspec.yaml:

dependencies:
  coderspace_network: ^latest_version

📖 Usage

✅ Import

// Import the package
import 'package:coderspace_network/coderspace_network.dart';

✅ Initialize CoderClient

// Create an instance with your base URL
final client = CoderClient(baseUrl: 'https://jsonplaceholder.typicode.com');
// OR
final client = CoderClient(
  baseUrl: 'https://your-api.com',
  timeout: const Duration(seconds: 15),
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
  },
);

✅ Make a GET request

final result = await client.get<List<Post>>(
  '/posts',
  // Use the parser to convert raw response to your model
  parser: (data) => ensureList(data, (e) => Post.fromJson(e)),
);

if (result.isSuccess) {
  final posts = result.data!;
  print('Fetched ${posts.length} posts');
} else {
  print('❌ Error: ${result.error}');
}

✅ Make a POST request

final result = await client.post<Map<String, dynamic>>(
  '/posts',
  data: {
    'title': 'Hello World',
    'body': 'This is a test post',
    'userId': 1,
  },
);

if (result.isSuccess) {
  print('✅ Created: ${result.data}');
} else {
  print('❌ Failed: ${result.error}');
}

✅ Handling Single or List Response

If the API may return a single item or a list, use ensureList:

final users = ensureList(responseData, (e) => User.fromJson(e));

🚀 About Me

👨‍💻 Senior Flutter Developer
💡 One principle I always code by:
"Don’t just develop — Develop Innovative"

📝 Author Profile

coderspacedev
linkedin
Stack_Overflow

Support

For support, email thoriyaprahalad@gmail.com

About

coderspace_network is a lightweight, developer-friendly Flutter package for making REST API calls using Dio. It provides clean, generic request handling, consistent error management, and simple utilities like auto-list parsing—all with minimal code.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages