Skip to content

Standalone SSE Server Application written in Rust.

License

Notifications You must be signed in to change notification settings

Tibuarka/rust_sse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SSE

This is a library to implement server-sent events in a web application project. The library can be used to start a seperate dedicated http server which handels SSEs or can be used with your custom handlers with the axum web framework (I did not get it to work with other frameworks).

Examples

Standalone HTTP server

TODO

Integrated into axum with custom route handler

#[tokio::main]
async fn main() {
    // Let the maintenance run seperately
    task::spawn(async {
            SSE.maintenance(1).await;
        });

    // Moves the request to the SSE handler
    let app = Router::new().route("/event/:event",get( move |req| event_handler(req) ));

    // Start the server on port 8082
    let addr = SocketAddr::from(([127, 0, 0, 1], 8082));
    axum::Server::bind(&addr).serve(app.into_make_service()).await.expect("Failed starting the server");
}

async fn event_handler(req: Request<Body>) -> Response<Body> {
    SSE.create_stream(req)
}

WARNING

  • This is my first rust project so this code is by no means stable and/or good! Feel free to modify it to suit your needs
  • I will not accept pull requests because the amount of knowledge about rust that I have is not enough to correctly decide over your proposed changes
  • I do not maintain this repository actively and just may update some dependy versions

About

Standalone SSE Server Application written in Rust.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages