Skip to content

Instantly share code, notes, and snippets.

@masakielastic
Last active December 26, 2025 20:01
Show Gist options
  • Select an option

  • Save masakielastic/769f959e43beaed6e2c4c7975e1904d9 to your computer and use it in GitHub Desktop.

Select an option

Save masakielastic/769f959e43beaed6e2c4c7975e1904d9 to your computer and use it in GitHub Desktop.
Poem で Hello World

Poem で Hello World

プロジェクトを作成します。

cargo new poem-hello
cd poem-hello

Cargo.toml を編集します。

[dependencies]
poem = "1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

macro#[tokio::main] を使うために必要です。

src/main.rs を編集します。

use poem::{get, handler, Route, Server};
use poem::listener::TcpListener;

#[handler]
fn hello() -> &'static str {
    "Hello, world!"
}

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
    let app = Route::new().at("/", get(hello));

    Server::new(TcpListener::bind("127.0.0.1:3000"))
        .run(app)
        .await
}

ビルドおよび起動する

cargo run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment