RailsライクなRustのWebフレームワーク 「Loco」 | DevelopersIO これみたがいくつか誤りが有る
{"created_at":"2023-12-07T02:22:33.108351","updated_at":"2023-12-07T02:22:33.108351","id":11,"title":"Your Title","content":"Your Content xxx"}%
に対して、
続いてupdateとpk検索してみます。
とあるが、
% curl -X POST -H "Content-Type: application/json" -d '{ "title": "Your Title Update", "content": "Your Content xxx Update" }' localhost:3000/articles:11
このときに11を指定するのは、登録したときに id
が 11
のときなので注意だ。
さもないと
% curl localhost:3000/articles/11 {"created_at":"2023-12-07T02:22:33.108351","updated_at":"2023-12-07T02:22:33.108351","id":11,"title":"Your Title Update","content":"Your Content xxx Update"}%
で取得はできないはず。
scaffoldを使ってみよう
pub fn routes() -> Routes { Routes::new() .prefix("articles") .add("/", get(list)) .add("/", post(add)) .add("/:id", get(get_one)) .add("/:id", delete(remove)) .add("/:id", post(update)) .add("/:id/comments", get(comments)) }
ここで
.add("/:id/comments", get(comments))
も追加を忘れずに!