Commit graph

6 commits

Author SHA1 Message Date
Laurențiu Nicola
68f826ef3b
Simplify tracing-subscriber initialization (#128) 2021-08-05 19:43:03 +02:00
Spencer Gilbert
3cd0c0fd45
Set RUST_LOG environment var for all examples using tracing (#123)
* Set RUST_LOG environment var for all examples using tracing

Signed-off-by: Spencer Gilbert <spencer.gilbert@gmail.com>

* Update examples/multipart_form.rs

Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
2021-08-05 11:25:03 +02:00
David Pedersen
5c12328892
Replace hyper::Server with axum::Server in docs (#118)
* Replace `hyper::Server` with `axum::Server` in docs

* Change readme as well
2021-08-04 15:38:51 +02:00
Jonas Platte
015f6e0c21
Fix typos found by typos-cli (#113) 2021-08-04 12:09:39 +02:00
David Pedersen
9fbababc3a
Make it clear how to run all examples (#92)
* Handle errors in websocket example

* Make it clear how to run all examples
2021-08-02 23:09:09 +02:00
David Pedersen
6d787665d6
Server-Sent Events (#75)
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)
2021-08-01 21:49:17 +02:00