mirror of
				https://github.com/ivanch/tcc.git
				synced 2025-10-31 01:17:37 +00:00 
			
		
		
		
	testando rust
This commit is contained in:
		
							
								
								
									
										40
									
								
								ActixAPI/src/main.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								ActixAPI/src/main.rs
									
									
									
									
									
										Normal 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 | ||||
| } | ||||
		Reference in New Issue
	
	Block a user