mirror of
https://github.com/tokio-rs/axum.git
synced 2025-03-28 01:10:38 +01:00
Example usage: ```rust use axum::{prelude::*, sse::{sse, Event, KeepAlive}}; use tokio_stream::StreamExt as _; use futures::stream::{self, Stream}; use std::{ time::Duration, convert::Infallible, }; let app = route("/sse", sse(make_stream).keep_alive(KeepAlive::default())); async fn make_stream( // you can also put extractors here ) -> Result<impl Stream<Item = Result<Event, Infallible>>, Infallible> { // A `Stream` that repeats an event every second let stream = stream::repeat_with(|| Event::default().data("hi!")) .map(Ok) .throttle(Duration::from_secs(1)); Ok(stream) } ``` Implementation is based on [warp's](https://github.com/seanmonstar/warp/blob/master/src/filters/sse.rs) |
||
---|---|---|
.. | ||
self_signed_certs | ||
sse | ||
templates | ||
websocket | ||
error_handling_and_dependency_injection.rs | ||
form.rs | ||
hello_world.rs | ||
key_value_store.rs | ||
multipart_form.rs | ||
README.md | ||
sessions.rs | ||
sse.rs | ||
static_file_server.rs | ||
templates.rs | ||
testing.rs | ||
tls_rustls.rs | ||
todos.rs | ||
tokio_postgres.rs | ||
unix_domain_socket.rs | ||
versioning.rs | ||
websocket.rs |
Examples
hello_world
- Very small getting started app.todos
- Provides a RESTful web server managing some Todos.key_value_store
- Slightly larger app with an in-memory key/value store.form
- Receiving data from an HTML<form>
.multipart_form
- How to parsemultipart/form-data
forms.static_file_server
- Serving static files from a directory. Could for example be the baseline for a single page app.templates
- Rending HTML templates using askama.testing
- How to test axum apps.versioning
- How one might version an API.websocket
- How to build an app that handles WebSocket connections.error_handling_and_dependency_injection
- How to handle errors and dependency injection using trait objects.tokio_postgres
- How to use a tokio-postgres and bb8 to query a database.unix_domain_socket
- How to run an Axum server over unix domain sockets.sessions
- Sessions and cookies usingasync-session
.tls_rustls
- TLS withtokio-rustls
.