첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

■ Actix Web 프레임워크를 사용해 초간단 웹 서버를 만드는 방법을 보여준다.

test_server.zip
0.03MB

▶ 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
그리드형(광고전용)
Posted by icodebroker
,