■ Actix Web 프레임워크를 사용해 단순 웹 서버를 만드는 방법을 보여준다.
▶ Cargo.toml
1 2 3 4 5 6 7 8 9 |
[package] name = "test_server" version = "0.1.0" edition = "2021" [dependencies] actix-web = "3" |
▶ src/main.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
use actix_web; const SERVER_ADDRESS : &str = "127.0.0.1:8888"; #[actix_web::main] async fn main() -> Result<(), actix_web::Error> { println!("[서버] http://{}/", SERVER_ADDRESS); actix_web::HttpServer::new ( || { actix_web::App::new().route("/", actix_web::web::get().to(index)) } ) .bind(SERVER_ADDRESS)? .run() .await?; return Ok(()); } async fn index(request : actix_web::HttpRequest) -> Result<actix_web::HttpResponse, actix_web::Error> { println!("요청 : {:?}", request); let result : &str = "안녕하세요."; Ok(actix_web::HttpResponse::Ok().body(result)) } |