testando rust

This commit is contained in:
2023-09-12 21:39:28 -03:00
parent 1dbd8c238f
commit cd1e9da710
6 changed files with 1379 additions and 0 deletions

40
ActixAPI/src/main.rs Normal file
View File

@@ -0,0 +1,40 @@
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder, HttpRequest, Result};
use actix_files::NamedFile;
use std::path::PathBuf;
#[get("/status/ok")]
async fn hello() -> impl Responder {
HttpResponse::Ok().body("{\"status\": 200}")
}
#[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!")
}
async fn static_serve(req: HttpRequest) -> Result<NamedFile> {
let path: &str = req.path();
let real_path = &path[1..];
Ok(NamedFile::open(real_path)?)
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
println!("Hello, world!");
HttpServer::new(|| {
App::new()
.route("/static/{filename:.*}", web::get().to(static_serve))
.service(hello)
.service(echo)
.route("/hey", web::get().to(manual_hello))
})
.bind(("0.0.0.0", 9090))?
.run()
.await
}