aim_server_sse 0.0.1
aim_server_sse: ^0.0.1 copied to clipboard
Server-Sent Events (SSE) support for aim_server with real-time streaming capabilities.
0.0.1 #
Initial release - Server-Sent Events (SSE) support for Aim framework
Features #
- Server-Sent Events streaming with
c.sse()extension method SseStreamAPI with convenient methods:send()for sending text eventssendJson()for sending JSON-encoded eventskeepAlive()for connection keep-alivecomment()for debug comments
- Support for event types, IDs, and retry intervals
- Automatic connection cleanup on callback completion or error
- Proper SSE protocol formatting with multi-line data support
- Type-safe event handling with
SseEventclass
Examples #
import 'package:aim_server/aim_server.dart';
import 'package:aim_server_sse/aim_server_sse.dart';
final app = Aim();
// Basic SSE
app.get('/events', (c) async {
return c.sse((stream) async {
stream.send('Hello, SSE!');
stream.sendJson({'message': 'World!'}, event: 'greeting');
});
});
// Real-time updates
app.get('/clock', (c) async {
return c.sse((stream) async {
while (true) {
stream.sendJson({'time': DateTime.now().toIso8601String()});
await Future.delayed(Duration(seconds: 1));
}
});
});