mirror of
https://github.com/actix/actix-website
synced 2025-06-27 07:29:02 +02:00
Responses section is done-ish.
This commit is contained in:
@ -1,16 +1,22 @@
|
||||
// <auto>
|
||||
use actix_web::{
|
||||
http::ContentEncoding, middleware, web, App, HttpRequest, HttpResponse,
|
||||
};
|
||||
use actix_web::{http::ContentEncoding, middleware, HttpResponse};
|
||||
|
||||
fn index(_req: HttpRequest) -> HttpResponse {
|
||||
fn index() -> HttpResponse {
|
||||
HttpResponse::Ok().body("data")
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
App::new()
|
||||
// v- disable compression for all routes
|
||||
.wrap(middleware::Compress::new(ContentEncoding::Identity))
|
||||
.route("/", web::get().to(index));
|
||||
use actix_web::{web, App, HttpServer};
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
// v- disable compression for all routes
|
||||
.wrap(middleware::Compress::new(ContentEncoding::Identity))
|
||||
.route("/", web::get().to(index))
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
// </auto>
|
||||
|
@ -1,16 +1,19 @@
|
||||
// <brotli>
|
||||
use actix_web::{
|
||||
http::ContentEncoding, middleware::BodyEncoding, HttpRequest, HttpResponse,
|
||||
};
|
||||
use actix_web::{http::ContentEncoding, middleware::BodyEncoding, HttpResponse};
|
||||
|
||||
fn index_br(_req: HttpRequest) -> HttpResponse {
|
||||
fn index_br() -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
.encoding(ContentEncoding::Br)
|
||||
.body("data")
|
||||
}
|
||||
// </brotli>
|
||||
|
||||
use actix_web::{web, App};
|
||||
pub fn main() {
|
||||
App::new().route("/", web::get().to(index_br));
|
||||
use actix_web::{web, App, HttpServer};
|
||||
|
||||
HttpServer::new(|| App::new().route("/", web::get().to(index_br)))
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
|
@ -11,4 +11,13 @@
|
||||
// ))))))
|
||||
// }
|
||||
// </chunked>
|
||||
pub fn main() {}
|
||||
|
||||
// pub fn main() {
|
||||
// use actix_web::{web, App, HttpServer};
|
||||
|
||||
// HttpServer::new(|| App::new().route("/", web::get().to(index)))
|
||||
// .bind("127.0.0.1:8088")
|
||||
// .unwrap()
|
||||
// .run()
|
||||
// .unwrap();
|
||||
// }
|
||||
|
@ -1,9 +1,7 @@
|
||||
// <identity>
|
||||
use actix_web::{
|
||||
http::ContentEncoding, middleware::BodyEncoding, HttpRequest, HttpResponse,
|
||||
};
|
||||
use actix_web::{http::ContentEncoding, middleware::BodyEncoding, HttpResponse};
|
||||
|
||||
fn index(_req: HttpRequest) -> HttpResponse {
|
||||
fn index() -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
// v- disable compression
|
||||
.encoding(ContentEncoding::Identity)
|
||||
@ -11,7 +9,12 @@ fn index(_req: HttpRequest) -> HttpResponse {
|
||||
}
|
||||
// </identity>
|
||||
|
||||
use actix_web::{web, App};
|
||||
pub fn main() {
|
||||
App::new().route("/", web::get().to(index));
|
||||
use actix_web::{web, App, HttpServer};
|
||||
|
||||
HttpServer::new(|| App::new().route("/", web::get().to(index)))
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
|
@ -17,7 +17,12 @@ pub fn index(_req: HttpRequest) -> HttpResponse {
|
||||
}
|
||||
// </identity-two>
|
||||
|
||||
use actix_web::{web, App};
|
||||
pub fn main() {
|
||||
App::new().route("/", web::get().to(index));
|
||||
use actix_web::{web, App, HttpServer};
|
||||
|
||||
HttpServer::new(|| App::new().route("/", web::get().to(index)))
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
|
@ -1,19 +1,25 @@
|
||||
// <json-resp>
|
||||
use actix_web::{web, App, HttpRequest, Result};
|
||||
use serde::Serialize;
|
||||
use actix_web::{web, HttpResponse, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct MyObj {
|
||||
name: String,
|
||||
}
|
||||
|
||||
fn index(req: HttpRequest) -> Result<web::Json<MyObj>> {
|
||||
Ok(web::Json(MyObj {
|
||||
name: req.match_info().query("name").to_string(),
|
||||
fn index(obj: web::Path<MyObj>) -> Result<HttpResponse> {
|
||||
Ok(HttpResponse::Ok().json(MyObj {
|
||||
name: obj.name.to_string(),
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
App::new().route(r"/a/{name}", web::get().to(index));
|
||||
use actix_web::{App, HttpServer};
|
||||
|
||||
HttpServer::new(|| App::new().route(r"/a/{name}", web::get().to(index)))
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
// </json-resp>
|
||||
|
@ -4,12 +4,11 @@ pub mod chunked;
|
||||
pub mod identity;
|
||||
pub mod identity_two;
|
||||
pub mod json_resp;
|
||||
// <builder>
|
||||
use actix_web::{
|
||||
http::ContentEncoding, middleware::BodyEncoding, HttpRequest, HttpResponse,
|
||||
};
|
||||
|
||||
fn index(_req: HttpRequest) -> HttpResponse {
|
||||
// <builder>
|
||||
use actix_web::{http::ContentEncoding, middleware::BodyEncoding, HttpResponse};
|
||||
|
||||
fn index() -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
.encoding(ContentEncoding::Br)
|
||||
.content_type("plain/text")
|
||||
@ -18,7 +17,12 @@ fn index(_req: HttpRequest) -> HttpResponse {
|
||||
}
|
||||
// </builder>
|
||||
|
||||
use actix_web::{web, App};
|
||||
pub fn main() {
|
||||
App::new().route("/", web::get().to(index));
|
||||
use actix_web::{web, App, HttpServer};
|
||||
|
||||
HttpServer::new(|| App::new().route("/", web::get().to(index)))
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
|
Reference in New Issue
Block a user