mirror of
https://github.com/actix/actix-website
synced 2025-06-27 07:29:02 +02:00
update examples to v4 (#258)
This commit is contained in:
@ -4,7 +4,7 @@ version = "1.0.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "3"
|
||||
actix-web = "4"
|
||||
serde = "1.0"
|
||||
futures = "0.3.1"
|
||||
bytes = "0.5"
|
||||
|
@ -1,5 +1,5 @@
|
||||
// <auto>
|
||||
use actix_web::{get, http::ContentEncoding, middleware, App, HttpResponse, HttpServer};
|
||||
use actix_web::{get, middleware, App, HttpResponse, HttpServer};
|
||||
|
||||
#[get("/")]
|
||||
async fn index() -> HttpResponse {
|
||||
@ -10,10 +10,10 @@ async fn index() -> HttpResponse {
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.wrap(middleware::Compress::new(ContentEncoding::Br))
|
||||
.wrap(middleware::Compress::default())
|
||||
.service(index)
|
||||
})
|
||||
.bind("127.0.0.1:8080")?
|
||||
.bind(("127.0.0.1", 8080))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
@ -1,13 +1,9 @@
|
||||
// <brotli>
|
||||
use actix_web::{
|
||||
dev::BodyEncoding, get, http::ContentEncoding, middleware, App, HttpResponse, HttpServer,
|
||||
};
|
||||
use actix_web::{get, middleware, App, HttpResponse, HttpServer};
|
||||
|
||||
#[get("/")]
|
||||
async fn index_br() -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
.encoding(ContentEncoding::Br)
|
||||
.body("data")
|
||||
HttpResponse::Ok().body("data")
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
@ -17,7 +13,7 @@ async fn main() -> std::io::Result<()> {
|
||||
.wrap(middleware::Compress::default())
|
||||
.service(index_br)
|
||||
})
|
||||
.bind("127.0.0.1:8080")?
|
||||
.bind(("127.0.0.1", 8080))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ async fn main() -> std::io::Result<()> {
|
||||
.wrap(middleware::Compress::new(ContentEncoding::Br))
|
||||
.route("/", web::get().to(index_br))
|
||||
})
|
||||
.bind("127.0.0.1:8080")?
|
||||
.bind(("127.0.0.1", 8080))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::io;
|
||||
|
||||
// <chunked>
|
||||
use actix_web::{get, web, App, Error, HttpRequest, HttpResponse, HttpServer};
|
||||
use futures::future::ok;
|
||||
@ -10,9 +12,10 @@ async fn index(_req: HttpRequest) -> HttpResponse {
|
||||
// </chunked>
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() {
|
||||
async fn main() -> io::Result<()> {
|
||||
HttpServer::new(|| App::new().service(index))
|
||||
.bind("127.0.0.1:8080")
|
||||
.bind(("127.0.0.1", 8080))
|
||||
.unwrap()
|
||||
.run();
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ async fn main() -> std::io::Result<()> {
|
||||
.wrap(middleware::Compress::default())
|
||||
.service(index_br)
|
||||
})
|
||||
.bind("127.0.0.1:8080")?
|
||||
.bind(("127.0.0.1", 8080))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
// <identity>
|
||||
use actix_web::{
|
||||
dev::BodyEncoding, get, http::ContentEncoding, middleware, App, HttpResponse, HttpServer,
|
||||
get, http::header::ContentEncoding, middleware, App, HttpResponse, HttpServer,
|
||||
};
|
||||
|
||||
#[get("/")]
|
||||
async fn index() -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
// v- disable compression
|
||||
.encoding(ContentEncoding::Identity)
|
||||
.insert_header(ContentEncoding::Identity)
|
||||
.body("data")
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ async fn main() -> std::io::Result<()> {
|
||||
.wrap(middleware::Compress::default())
|
||||
.service(index)
|
||||
})
|
||||
.bind("127.0.0.1:8080")?
|
||||
.bind(("127.0.0.1", 8080))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
// <identity-two>
|
||||
use actix_web::{
|
||||
dev::BodyEncoding, get, http::ContentEncoding, middleware, App, HttpResponse, HttpServer,
|
||||
get, http::header::ContentEncoding, middleware, App, HttpResponse, HttpServer,
|
||||
};
|
||||
|
||||
static HELLO_WORLD: &[u8] = &[
|
||||
0x1f, 0x8b, 0x08, 0x00, 0xa2, 0x30, 0x10, 0x5c, 0x00, 0x03, 0xcb, 0x48, 0xcd, 0xc9, 0xc9, 0x57,
|
||||
0x28, 0xcf, 0x2f, 0xca, 0x49, 0xe1, 0x02, 0x00, 0x2d, 0x3b, 0x08, 0xaf, 0x0c, 0x00, 0x00, 0x00,
|
||||
0x1f, 0x8b, 0x08, 0x00, 0xa2, 0x30, 0x10, 0x5c, 0x00, 0x03, 0xcb, 0x48, 0xcd, 0xc9, 0xc9,
|
||||
0x57, 0x28, 0xcf, 0x2f, 0xca, 0x49, 0xe1, 0x02, 0x00, 0x2d, 0x3b, 0x08, 0xaf, 0x0c, 0x00,
|
||||
0x00, 0x00,
|
||||
];
|
||||
|
||||
#[get("/")]
|
||||
async fn index() -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
.encoding(ContentEncoding::Identity)
|
||||
.header("content-encoding", "gzip")
|
||||
.insert_header(ContentEncoding::Gzip)
|
||||
.body(HELLO_WORLD)
|
||||
}
|
||||
// </identity-two>
|
||||
@ -24,7 +24,7 @@ async fn main() -> std::io::Result<()> {
|
||||
.wrap(middleware::Compress::default())
|
||||
.service(index)
|
||||
})
|
||||
.bind("127.0.0.1:8080")?
|
||||
.bind(("127.0.0.1", 8080))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ async fn main() -> std::io::Result<()> {
|
||||
use actix_web::{App, HttpServer};
|
||||
|
||||
HttpServer::new(|| App::new().service(index))
|
||||
.bind("127.0.0.1:8080")?
|
||||
.bind(("127.0.0.1", 8080))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ pub mod identity_two;
|
||||
pub mod json_resp;
|
||||
|
||||
// <builder>
|
||||
use actix_web::HttpResponse;
|
||||
use actix_web::{http::header::ContentType, HttpResponse};
|
||||
|
||||
async fn index() -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/plain")
|
||||
.header("X-Hdr", "sample")
|
||||
.content_type(ContentType::plaintext())
|
||||
.insert_header(("X-Hdr", "sample"))
|
||||
.body("data")
|
||||
}
|
||||
// </builder>
|
||||
@ -22,7 +22,7 @@ async fn main() -> std::io::Result<()> {
|
||||
use actix_web::{web, App, HttpServer};
|
||||
|
||||
HttpServer::new(|| App::new().route("/", web::get().to(index)))
|
||||
.bind("127.0.0.1:8080")?
|
||||
.bind(("127.0.0.1", 8080))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
Reference in New Issue
Block a user