LoginSignup
3
0

More than 1 year has passed since last update.

【自分用備忘録】res.status().json と res.status().send の違い

Posted at

初めまして。hojojoです。

Expressを触っていて、

res.status().json
res.status().send

の違いが分からなくなってきたので整理してみました。

以下の記事を見つけたのですが、結果は変わらないのでやっぱり同じっぽいですね。

じゃあ、好きは法を使えばいいよね!
だと納得いかなかったので、知り合いに聞いてみたら

・ res.send()はjson形式のデータではない簡単な文字列を返すときに使っている
・ res.json()はjson形式データを返す際に、明示的に分かりやすくするために使っている
・ apiを作る際はほとんどres.json()を使っている

だそうです。なるほど。
もし違う使い分けをされている方がいれば、コメント欄で教えてください。

3
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
3
0