2019-06-20 02:04:22 -04:00
|
|
|
// <stream>
|
2019-06-28 13:31:30 -04:00
|
|
|
use actix_web::{Error, HttpResponse};
|
2019-06-15 16:37:08 -04:00
|
|
|
use bytes::Bytes;
|
|
|
|
use futures::stream::once;
|
|
|
|
|
2019-06-28 13:31:30 -04:00
|
|
|
fn index() -> HttpResponse {
|
2019-06-20 02:04:22 -04:00
|
|
|
let body = once::<Bytes, Error>(Ok(Bytes::from_static(b"test")));
|
2019-06-15 16:37:08 -04:00
|
|
|
|
|
|
|
HttpResponse::Ok()
|
|
|
|
.content_type("application/json")
|
2019-06-20 02:04:22 -04:00
|
|
|
.streaming(Box::new(body))
|
2019-06-15 16:37:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2019-06-28 13:31:30 -04:00
|
|
|
use actix_web::{web, App, HttpServer};
|
|
|
|
|
2019-06-20 02:04:22 -04:00
|
|
|
HttpServer::new(|| App::new().route("/async", web::to_async(index)))
|
|
|
|
.bind("127.0.0.1:8088")
|
|
|
|
.unwrap()
|
|
|
|
.run()
|
|
|
|
.unwrap();
|
2019-06-15 16:37:08 -04:00
|
|
|
}
|
2019-06-20 02:04:22 -04:00
|
|
|
// </stream>
|