add actix example
This commit is contained in:
parent
e98f9517fb
commit
1fa926dd05
2 changed files with 29 additions and 5 deletions
|
@ -5,4 +5,5 @@ edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix = "0.13"
|
actix = "0.13"
|
||||||
tokio = { version = "1.44", features = ["full"] }
|
actix-web = "4.10"
|
||||||
|
#tokio = { version = "1.44", features = ["full"] } maybe
|
||||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -1,5 +1,28 @@
|
||||||
#[tokio::main]
|
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
println!("Hello, world!");
|
#[get("/")]
|
||||||
Ok(())
|
async fn hello() -> impl Responder {
|
||||||
|
HttpResponse::Ok().body("Hello world!")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[post("/echo")]
|
||||||
|
async fn echo(req_body: String) -> impl Responder {
|
||||||
|
HttpResponse::Ok().body(req_body)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn manual_hello() -> impl Responder {
|
||||||
|
HttpResponse::Ok().body("Hey there!")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
|
HttpServer::new(|| {
|
||||||
|
App::new()
|
||||||
|
.service(hello)
|
||||||
|
.service(echo)
|
||||||
|
.route("/hey", web::get().to(manual_hello))
|
||||||
|
})
|
||||||
|
.bind(("127.0.0.1", 8080))?
|
||||||
|
.run()
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue