summaryrefslogtreecommitdiff
path: root/actix/src/main.rs
diff options
context:
space:
mode:
authorxengineering <mail2xengineering@protonmail.com>2021-03-01 14:16:47 +0100
committerxengineering <mail2xengineering@protonmail.com>2021-03-01 14:16:47 +0100
commitfcfffa47accad303bd9d927502396d8e4174c234 (patch)
tree277db3e6c2b2e9593fe3afd2c8dbf22747e74f99 /actix/src/main.rs
parent7c461d3ed31a1805b30e5701873ad702a64ba0de (diff)
downloadweb-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.rs30
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
+}
+