Closed notrab closed 1 month ago
This PR adds proper SSE responses for the /beta/listen endpoint. The previous behaviour used JSON Line formatting.
/beta/listen
error
handle_listen
SseStream
Sse
The below is now possible:
const eventSource = new EventSource('http://127.0.0.1:8080/beta/listen?table=mytable&action=insert,update'); eventSource.onmessage = (event) => { const data = JSON.parse(event.data); console.log('Received changes:', data); }; eventSource.onerror = (error) => { console.error('EventSource failed:', error); }; eventSource.addEventListener('error', (event) => { const errorMessage = event.data; console.error('Server error:', errorMessage); }); // To close the connection // eventSource.close();
Tested locally and events are being sent out in the correct format as shown in the attached Postman screenshot.
This PR adds proper SSE responses for the
/beta/listen
endpoint. The previous behaviour used JSON Line formatting.Changes
error
event type) and event filtering to work with the new SSE format.handle_listen
to return anSseStream
.Sse
handles this automatically.Example Usage
The below is now possible: