0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

axumで単一パラメータのQueryパースに失敗する

Posted at

axumをつかっていてクエリパラメータがなんか取れないな?ってことがあったので備忘録

現象

以下のような関数をapi呼び出しした際、Queryの取得に失敗してました
Query<Uuid> が受け取れずエラーになってました

asyn fn get_user(Query(user_id): Query<Uuid>) -> Result<User, String> {
    // ...
}

原因と対策

原因としてはQueryのような型宣言では単一パラメータのパースはできませんでした
以下のように構造体内にパラメータのフィールドを宣言する必要があるようです

#[derive(Serialize)]
pub struct GetUser {
    user_id: Uuid;
}

もしかするとi32などのプリミティブな型だとパースできるのかもしれませんが参考までに!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?