Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第二部 - サーバーとの通信 #42

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/chapter2/section2/2_fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
## pingページの作成

接続の練習のためサーバーに`/ping`エンドポイントを実装しておきましょう。
サーバーのリポジトリの`main.go`の`main`関数を書き換えます
サーバーのリポジトリの`handler.rs`を書き換えます

<<<@/chapter2/section2/src/2/main.go{go:line-numbers}
<<<@/chapter2/section2/src/2/handler.rs{rs:line-numbers}

次にフロントエンドから`/ping`エンドポイントにアクセスしてみるコードを書いてみましょう。

Expand Down
27 changes: 27 additions & 0 deletions docs/chapter2/section2/src/2/handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use axum::{
routing::{get, post},
Router,
};

use crate::repository::Repository;

mod auth;
mod country;

pub fn make_router(app_state: Repository) -> Router {
let city_router = Router::new()
.route("/cities/:city_name", get(country::get_city_handler))
.route("/cities", post(country::post_city_handler));

let auth_router = Router::new()
.route("/signup", post(auth::sign_up))
.route("/login", post(auth::login));

let ping_router = Router::new().route("/ping", get(|| async { "pong" })); // [!code ++]

Router::new()
.nest("/", city_router)
.nest("/", auth_router)
.nest("/", ping_router) // [!code ++]
.with_state(app_state)
}
12 changes: 0 additions & 12 deletions docs/chapter2/section2/src/2/main.go

This file was deleted.

Loading