포트폴리오 - 웹프레임워크

갤럭시4414·2022년 11월 3일
0

웹 서비스를 만드려면 웹 프레임워크를 선택해야 한다는데, 찾아보니 Rust 로는 요런게 있나보다.

Actix Web - https://actix.rs/
Rocket - https://rocket.rs/
Axum - https://github.com/tokio-rs/axum
Graphul - https://github.com/graphul-rs/graphul

문서를 봐도 잘 모르겠고, 다 비슷비슷한 것 같아서 이름이 맘에 드는 Rocket 으로 정했다.

일단 디펜던시에 rocket을 추가한다. 버전이 rc.2 인게 신경쓰이지만 공식 문서 에 이렇게 써있으니 0.5.0-rc.2 로 써보자.

backend/Cargo.toml

[package]
name = "backend"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rocket = "0.5.0-rc.2"

cargo run 으로 실행을 하니 뭔가 열심히 다운로드 받는다. 하지만 결과는 Hello World 이니, main.rs 코드를 샘플로 바꿔치기 해보자.

backend/src/main.rs

#[macro_use] extern crate rocket;

#[get("/")]
fn index() -> &'static str {
    "Hello, world!"
}

#[launch]
fn rocket() -> _ {
    rocket::build().mount("/", routes![index])
}

cargo run 으로 실행하니 뭔가 주저리주저리 나오고 url 스러운게 나온다.

📬 Routes:
   >> (index) GET /
📡 Fairings:
   >> Shield (liftoff, response, singleton)
🛡️ Shield:
   >> X-Content-Type-Options: nosniff
   >> Permissions-Policy: interest-cohort=()
   >> X-Frame-Options: SAMEORIGIN
🚀 Rocket has launched from http://127.0.0.1:8000

짜잔!

뭔가 반에반은 한 느낌이다.

profile
풀스택개발자를꿈꾸는

0개의 댓글