coderspace_network 1.0.2
coderspace_network: ^1.0.2 copied to clipboard
A lightweight and developer-friendly Dio-based HTTP client for Flutter with clean response handling and model parsing.
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 #
Support #
For support, email thoriyaprahalad@gmail.com