did some inital testing with actix
Some checks failed
Test Gitea Actions / first (push) Successful in 14s
Test Gitea Actions / check-code (push) Failing after 12s
Test Gitea Actions / test (push) Has been skipped
Test Gitea Actions / documentation-check (push) Has been skipped

This commit is contained in:
2025-02-27 16:30:59 -07:00
parent efdb732c96
commit ad92fedb9c
6 changed files with 1577 additions and 2 deletions

1510
actix_web_learning/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
[package]
name = "actix_web_learning"
version = "0.1.0"
edition = "2024"
[dependencies]
actix-web = "4"
serde = { version = "1.0", features = ["derive"] }

View File

@ -0,0 +1,40 @@
use actix_web::{get, post, HttpResponse, Responder};
pub fn add(left: u64, right: u64) -> u64 {
left + right
}
#[get("/")]
pub async fn hello() -> impl Responder {
HttpResponse::Ok().body("Hello world!")
}
#[post("/echo")]
pub async fn echo(req_body: String) -> impl Responder {
HttpResponse::Ok().body(req_body)
}
pub async fn manual_hello() -> impl Responder {
HttpResponse::Ok().body("Hello there!\nGeneral Kenobi")
}
// the path to get to the html response
#[get("/resend")]
// function signature, data that is passed in, return type must implement the Responder trait
pub async fn resend(req_body: String) -> impl Responder {
// this returns a html response with a 200 code
// this should be used for final serialization
// possibly main functionality
HttpResponse::Ok().body(req_body)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}

View File

@ -0,0 +1,17 @@
use actix_web::{web, App, HttpServer};
use actix_web_learning::{hello, echo, resend, manual_hello};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.service(hello)
.service(echo)
.service(resend)
.route("/hey", web::get().to(manual_hello))
})
.bind(("darkicen950.local", 8080))?
.run()
.await
}