diff options
author | xengineering <mail2xengineering@protonmail.com> | 2021-03-01 14:16:47 +0100 |
---|---|---|
committer | xengineering <mail2xengineering@protonmail.com> | 2021-03-01 14:16:47 +0100 |
commit | fcfffa47accad303bd9d927502396d8e4174c234 (patch) | |
tree | 277db3e6c2b2e9593fe3afd2c8dbf22747e74f99 /actix/src/main.rs | |
parent | 7c461d3ed31a1805b30e5701873ad702a64ba0de (diff) | |
download | web-template-fcfffa47accad303bd9d927502396d8e4174c234.tar web-template-fcfffa47accad303bd9d927502396d8e4174c234.tar.zst web-template-fcfffa47accad303bd9d927502396d8e4174c234.zip |
Actix Example
Diffstat (limited to 'actix/src/main.rs')
-rw-r--r-- | actix/src/main.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/actix/src/main.rs b/actix/src/main.rs new file mode 100644 index 0000000..4f03d08 --- /dev/null +++ b/actix/src/main.rs @@ -0,0 +1,30 @@ + +use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder}; + +#[get("/")] +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 +} + |