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.
Add this to your pubspec.yaml
:
dependencies:
coderspace_network: ^latest_version
// Import the package
import 'package:coderspace_network/coderspace_network.dart';
// 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',
},
);
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}');
}
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}');
}
If the API may return a single item or a list, use ensureList:
final users = ensureList(responseData, (e) => User.fromJson(e));
👨💻 Senior Flutter Developer
💡 One principle I always code by:
"Don’t just develop — Develop Innovative"
For support, email thoriyaprahalad@gmail.com