coderspace_network 1.0.2 copy "coderspace_network: ^1.0.2" to clipboard
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 #

coderspacedev
linkedin
Stack_Overflow

Support #

For support, email thoriyaprahalad@gmail.com

0
likes
160
points
59
downloads

Publisher

verified publishercoderdev.space

Weekly Downloads

A lightweight and developer-friendly Dio-based HTTP client for Flutter with clean response handling and model parsing.

Homepage
Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

dio, flutter, mockito

More

Packages that depend on coderspace_network