ispectify_http 4.2.0
ispectify_http: ^4.2.0 copied to clipboard
An additional package for http (logging and handling).
🔍 Overview #
ISpectify HTTP provides seamless integration between the http_interceptor package and the ISpectify logging system.
🌐 HTTP Logging • 📊 Response Tracking • ❌ Error Handling • ⚡ Performance
Enhance your HTTP debugging workflow by automatically capturing and logging all HTTP client interactions using the http_interceptor package. Provides seamless integration with Dart's HTTP package through interceptors for comprehensive request and response monitoring.
🎯 Key Features #
- 🌐 HTTP Request Logging: Automatic logging of all HTTP requests
- 📊 Response Tracking: Detailed response logging with timing information
- ❌ Error Handling: Comprehensive error logging with stack traces
- 🔍 Request Inspection: Headers, body, and parameter logging
- ⚡ Performance Metrics: Request/response timing and size tracking
- 🎛️ Lightweight: Minimal overhead using http_interceptor package
🔧 Configuration Options #
Basic Setup #
final http_interceptor.InterceptedClient client =
http_interceptor.InterceptedClient.build(interceptors: []);
// Initialize in ISpect.run onInit callback
ISpect.run(
() => runApp(MyApp()),
logger: iSpectify,
onInit: () {
client.interceptors.add(
ISpectifyHttpLogger(iSpectify: iSpectify),
);
},
);
File Upload Example #
// Upload file using MultipartRequest
final List<int> bytes = [1, 2, 3]; // File data
const String filename = 'file.txt';
final http_interceptor.MultipartRequest request =
http_interceptor.MultipartRequest(
'POST',
Uri.parse('https://api.example.com/upload'),
);
request.files.add(http_interceptor.MultipartFile.fromBytes(
'file', // Field name
bytes,
filename: filename,
));
// Send request - will be automatically logged
client.send(request);
📦 Installation #
Add ispectify_http to your pubspec.yaml
:
dependencies:
ispectify_http: ^4.1.4
🚀 Quick Start #
import 'package:flutter/material.dart';
import 'package:ispect/ispect.dart';
import 'package:http_interceptor/http_interceptor.dart' as http_interceptor;
import 'package:ispectify_http/ispectify_http.dart';
final http_interceptor.InterceptedClient client =
http_interceptor.InterceptedClient.build(interceptors: []);
void main() {
final ISpectify iSpectify = ISpectifyFlutter.init();
ISpect.run(
() => runApp(MyApp()),
logger: iSpectify,
onInit: () {
// Add ISpectify HTTP interceptor
client.interceptors.add(
ISpectifyHttpLogger(iSpectify: iSpectify),
);
},
);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('ISpectify HTTP Example')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () async {
// All HTTP requests will be automatically logged
await client.get(
Uri.parse('https://jsonplaceholder.typicode.com/posts/1'),
);
},
child: const Text('Send HTTP Request'),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () async {
// Error requests are also logged
await client.get(
Uri.parse('https://jsonplaceholder.typicode.com/invalid'),
);
},
child: const Text('Send Error Request'),
),
],
),
),
),
);
}
}
📚 Examples #
See the example/ directory for complete integration examples with different HTTP client configurations.
🏗️ Architecture #
ISpectifyHttp integrates with the standard HTTP client through interceptors:
Component | Description |
---|---|
HTTP Interceptor | Captures HTTP requests and responses |
Request Logger | Logs request details (headers, body, params) |
Response Logger | Logs response data and timing |
Error Handler | Captures and logs HTTP errors |
Performance Tracker | Measures request/response times |
🤝 Contributing #
Contributions are welcome! Please read our contributing guidelines and submit pull requests to the main branch.
📄 License #
This project is licensed under the MIT License - see the LICENSE file for details.
🔗 Related Packages #
- ispectify - Foundation logging system
- ispectify_dio - Dio HTTP client integration
- ispect - Main debugging interface
- http_interceptor - HTTP interceptor package for Dart