mirror of
https://github.com/actix/actix-website
synced 2025-06-27 15:39:02 +02:00
v3 (#188)
This commit is contained in:
@ -1,33 +1,31 @@
|
||||
// <setup>
|
||||
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
|
||||
// <handlers>
|
||||
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
|
||||
|
||||
async fn index() -> impl Responder {
|
||||
#[get("/")]
|
||||
async fn hello() -> impl Responder {
|
||||
HttpResponse::Ok().body("Hello world!")
|
||||
}
|
||||
|
||||
async fn index2() -> impl Responder {
|
||||
HttpResponse::Ok().body("Hello world again!")
|
||||
#[post("/echo")]
|
||||
async fn echo(req_body: String) -> impl Responder {
|
||||
HttpResponse::Ok().body(req_body)
|
||||
}
|
||||
// </setup>
|
||||
|
||||
// <macro-attributes>
|
||||
use actix_web::get;
|
||||
|
||||
#[get("/hello")]
|
||||
async fn index3() -> impl Responder {
|
||||
async fn manual_hello() -> impl Responder {
|
||||
HttpResponse::Ok().body("Hey there!")
|
||||
}
|
||||
// </macro-attributes>
|
||||
// </handlers>
|
||||
|
||||
// <main>
|
||||
#[actix_rt::main]
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.route("/", web::get().to(index))
|
||||
.route("/again", web::get().to(index2))
|
||||
.service(hello)
|
||||
.service(echo)
|
||||
.route("/hey", web::get().to(manual_hello))
|
||||
})
|
||||
.bind("127.0.0.1:8088")?
|
||||
.bind("127.0.0.1:8080")?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
Reference in New Issue
Block a user