mirror of
https://github.com/actix/actix-website
synced 2025-06-15 18:45:39 +02:00
22 lines
530 B
Rust
22 lines
530 B
Rust
// <stream>
|
|
use actix_web::{get, web, App, Error, HttpResponse, HttpServer};
|
|
use futures::{future::ok, stream::once};
|
|
|
|
#[get("/stream")]
|
|
async fn stream() -> HttpResponse {
|
|
let body = once(ok::<_, Error>(web::Bytes::from_static(b"test")));
|
|
|
|
HttpResponse::Ok()
|
|
.content_type("application/json")
|
|
.streaming(body)
|
|
}
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
HttpServer::new(|| App::new().service(stream))
|
|
.bind(("127.0.0.1", 8080))?
|
|
.run()
|
|
.await
|
|
}
|
|
// </stream>
|