forked from traPtitech/naro-text
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
第一部 - サーバーアプリケーションを作ってみよう
- Loading branch information
Showing
10 changed files
with
77 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use axum::{routing::get, Router}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
// 「/hello」というエンドポイントを設定する | ||
let app = Router::new().route("/hello", get(handler)); | ||
|
||
// ポート8080でリスナーを作成する | ||
let listener = tokio::net::TcpListener::bind("127.0.0.1:8080") | ||
.await | ||
.unwrap(); | ||
|
||
println!("listening on {}", listener.local_addr().unwrap()); | ||
|
||
// サーバーを起動する | ||
axum::serve(listener, app).await.unwrap(); | ||
} | ||
|
||
// 文字列「Hello, World.」をクライアントに返す | ||
async fn handler() -> String { | ||
String::from("Hello, World.") | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use axum::{routing::get, Router}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
// 「/hello」「/kenken」の2つのエンドポイントを持つアプリケーションを作成 | ||
let app = Router::new() | ||
.route("/hello", get(hello_handler)) | ||
.route("/kenken", get(me_handler)); | ||
|
||
// ポート8080でリスナーを作成する | ||
let listener = tokio::net::TcpListener::bind("127.0.0.1:8080") | ||
.await | ||
.unwrap(); | ||
|
||
println!("listening on {}", listener.local_addr().unwrap()); | ||
|
||
// サーバーを起動する | ||
axum::serve(listener, app).await.unwrap(); | ||
} | ||
|
||
// 文字列「Hello, World.」をクライアントに返す | ||
async fn hello_handler() -> String { | ||
String::from("Hello, World.") | ||
} | ||
|
||
// 自己紹介をクライアントに返す | ||
async fn me_handler() -> String { | ||
String::from( | ||
"始めまして、@kenkenです。\nきらら作品(特に恋する小惑星、スロウスタート)が好きです。", | ||
) | ||
} |