Fluxy Networking
High-performance native HTTP engine with global interceptors and auto-serialization.
Fluxy Networking (FluxyHttp)
Fluxy v0.1.9 introduces FluxyHttp, a high-performance, zero-dependency networking engine built directly on dart:io. It replaces the legacy Fx.fetch with a more robust, professional-grade infrastructure that eliminates external dependencies while providing a 100% reactive experience.
Core Features
- Zero-Dependency: No
dioorhttprequired. Built on nativedart:io. - Auto-Orchestration: Seamless integration with
Fluxy.httpandFx.httpfor global API access. - Global Interceptors: Native support for request/response interceptors (perfect for Auth and Logging).
- Automatic JSON: Requests and responses are automatically serialized/deserialized.
- Thread safe: Optimized for background execution in
fluxWorker.
Basic Usage
The engine is available globally via Fluxy.http or the shorthand Fx.http.
// GET request (Returns dynamic Map or List)
final user = await Fx.http.get('/users/1');
// POST request with body
final response = await Fx.http.post('/users', body: {
'name': 'John Doe',
'email': 'john@example.com'
});Global Interceptors
Interceptors allow you to centralize logic like adding Authorization headers or logging.
Fluxy.http.interceptors.add(FluxyInterceptor(
onRequest: (options) {
// Add Auth Token
options.headers['Authorization'] = 'Bearer $token';
return options; // Proceed with modified request
},
onResponse: (response) {
// Log response
print('Response: ${response.statusCode}');
return response;
},
onError: (error) {
if (error.statusCode == 401) {
// Handle unauthorized
}
return error;
}
));Reactive Implementation
Combine FluxyHttp with AsyncFlux for a completely managed UI state.
// Define an async flux that fetches data
final userFlux = fluxAsync(() => Fx.http.get('/profile'));
// Connect to UI
Fx(() => userFlux.when(
loading: () => Fx.loader(),
data: (user) => Fx.text("Welcome, ${user['name']}"),
error: (e) => Fx.text("Error: $e"),
))Instance-Based Access
For testing or multi-base-URL support, you can create isolated instances.
final github = FluxyHttp(
baseUrl: 'https://api.github.com',
headers: {'Accept': 'application/vnd.github.v3+json'},
);
final repo = await github.get('/repos/swaingithub/fluxy');Advanced Logic
FluxyHttp is designed to work with FluxController and reactive workers.
class SearchController extends FluxController {
final query = flux("");
// debounced search
late final searchResults = fluxAsync(() async {
if (query.value.isEmpty) return [];
return await Fx.http.get('/search', query: {'q': query.value});
}, debounce: 500.ms);
}Streaming API
For large responses or real-time data:
final stream = Fx.http.stream('/events');
stream.listen((chunk) => print('Received data chunk'));