Support custom SSE event #2415
Labels
A-axum
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
E-medium
Call for participation: Experience needed to fix: Medium / intermediate
Feature Request
Enable advanced customization of the SSE (Server-Sent Events) Event struct by introducing the EventExt trait.
Motivation
In certain use cases, users may require additional customization options for the SSE Event struct in the Axum library. For instance, Vercel AI SDK doesn't follow the standard and only accepts raw text. So it is impossible to use Axum which always includes the
key
such asdata
,id
, etc.Proposal
The proposed solution involves introducing a trait, EventExt, with methods for customizing the SSE Event. Users can implement this trait to add their own logic and fields to the event. The trait includes methods for setting the data field and finalizing the event.
Users can then implement this trait for the SSE Event struct at the application level to provide their own customizations.
This approach allows users to have fine-grained control over the SSE Event without modifying the core Axum library.
I also tried to implement in in this branch https://github.com/linrium/axum/tree/feat/support-custom-sse-event
Alternatives
The text was updated successfully, but these errors were encountered: