728x90
728x170
■ Actix Web 프레임워크를 사용해 초간단 웹 서버를 만드는 방법을 보여준다.
▶ Cargo.toml
[package]
name = "test_server"
version = "0.1.0"
edition = "2021"
[dependencies]
actix-web = "3"
▶ src/main.rs
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))
}
728x90
그리드형(광고전용)
'Rust > actix-web' 카테고리의 다른 글
[RUST/ACTIX-WEB] Actix Web 프레임워크를 사용해 BMI 판정 웹 서버 만들기 (0) | 2023.06.07 |
---|---|
[RUST/ACTIX-WEB] 크레이트 설치 : actix-web (0) | 2023.06.05 |