1
0
mirror of https://github.com/actix/actix-website synced 2025-06-27 07:29:02 +02:00
This commit is contained in:
Rob Ede
2020-09-12 16:21:54 +01:00
committed by GitHub
parent a0ce9f28e2
commit 4d8d53cea5
145 changed files with 1011 additions and 1461 deletions

View File

@ -5,6 +5,5 @@ edition = "2018"
workspace = "../"
[dependencies]
actix-web = "2.0"
actix-rt = "1.0"
actix-service = "1.0"
actix-web = "3"
actix-service = "1"

View File

@ -1,18 +1,23 @@
#![allow(dead_code)]
// <setup>
use actix_web::{web, App, Responder, HttpServer};
use actix_web::{web, App, HttpServer, Responder};
async fn index() -> impl Responder {
"Hello world!"
}
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new().service(
web::scope("/app").route("/index.html", web::get().to(index)),
// prefixes all resources and routes attached to it...
web::scope("/app")
// ...so this handles requests for `GET /app/index.html`
.route("/index.html", web::get().to(index)),
)
})
.bind("127.0.0.1:8088")?
.bind("127.0.0.1:8080")?
.run()
.await
}

View File

@ -1,24 +1,27 @@
#![allow(dead_code)]
use actix_web::{web, App, HttpResponse, HttpServer};
// <combine>
struct State1;
struct State2;
#[rustfmt::skip]
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.service(
web::scope("/app1")
.data(State1)
.route("/", web::to(|| HttpResponse::Ok())))
.route("/", web::to(|| HttpResponse::Ok())),
)
.service(
web::scope("/app2")
.data(State2)
.route("/", web::to(|| HttpResponse::Ok())))
.route("/", web::to(|| HttpResponse::Ok())),
)
})
.bind("127.0.0.1:8088")?
.bind("127.0.0.1:8080")?
.run()
.await
}

View File

@ -1,3 +1,5 @@
#![allow(dead_code)]
// <config>
use actix_web::{web, App, HttpResponse, HttpServer};
@ -19,7 +21,7 @@ fn config(cfg: &mut web::ServiceConfig) {
);
}
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
@ -27,7 +29,7 @@ async fn main() -> std::io::Result<()> {
.service(web::scope("/api").configure(scoped_config))
.route("/", web::get().to(|| HttpResponse::Ok().body("/")))
})
.bind("127.0.0.1:8088")?
.bind("127.0.0.1:8080")?
.run()
.await
}

View File

@ -8,7 +8,7 @@ pub mod state;
pub mod vh;
// <multi>
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
@ -20,7 +20,7 @@ async fn main() -> std::io::Result<()> {
)
.route("/", web::to(|| HttpResponse::Ok()))
})
.bind("127.0.0.1:8088")?
.bind("127.0.0.1:8080")?
.run()
.await
}

View File

@ -15,7 +15,7 @@ async fn index(data: web::Data<AppStateWithCounter>) -> String {
// </setup_mutable>
// <make_app_mutable>
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let counter = web::Data::new(AppStateWithCounter {
counter: Mutex::new(0),
@ -28,7 +28,7 @@ async fn main() -> std::io::Result<()> {
.app_data(counter.clone()) // <- register the created data
.route("/", web::get().to(index))
})
.bind("127.0.0.1:8088")?
.bind("127.0.0.1:8080")?
.run()
.await
}

View File

@ -1,16 +1,14 @@
use actix_web::{web, App, HttpRequest, Responder};
use actix_web::{get, web, App, HttpRequest, Responder};
#[get("/show")]
async fn show_users(_req: HttpRequest) -> impl Responder {
"unimplemented!"
}
#[rustfmt::skip]
// <scope>
#[actix_rt::main]
#[actix_web::main]
async fn main() {
App::new()
.service(
web::scope("/users")
.route("/show", web::get().to(show_users)));
let scope = web::scope("/users").service(show_users);
App::new().service(scope);
}
// </scope>

View File

@ -1,12 +1,12 @@
// <setup>
use actix_web::{web, App, HttpServer};
use std::sync::Mutex;
use actix_web::{get, web, App, HttpServer};
// This struct represents state
struct AppState {
app_name: String,
}
#[get("/")]
async fn index(data: web::Data<AppState>) -> String {
let app_name = &data.app_name; // <- get app_name
@ -15,16 +15,16 @@ async fn index(data: web::Data<AppState>) -> String {
// </setup>
// <start_app>
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.data(AppState {
app_name: String::from("Actix-web"),
})
.route("/", web::get().to(index))
.service(index)
})
.bind("127.0.0.1:8088")?
.bind("127.0.0.1:8080")?
.run()
.await
}

View File

@ -1,7 +1,7 @@
use actix_web::{guard, web, App, HttpResponse, HttpServer};
// <vh>
#[actix_rt::main]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
@ -17,7 +17,7 @@ async fn main() -> std::io::Result<()> {
)
.route("/", web::to(|| HttpResponse::Ok()))
})
.bind("127.0.0.1:8088")?
.bind("127.0.0.1:8080")?
.run()
.await
}