如果客户端向 REST API 发送错误类型的数据,我应该 return 出现什么 HTTP 错误?

What HTTP error should I return if client sends incorrect type of data to REST API?

假设我有一个页面要求用户发送 IDID 应该是 Integer。如果用户发送字母数字(或任何不符合 Integer 格式的内容),我应该 return 400 - Bad Request 还是 406 - Not Acceptable

由于 REST API 是基于请求的,400 - Bad request 似乎更明确并适应这种情况。

如果请求的媒体类型不受支持,406 将是正确的。

422 可能就是您要找的;参见 https://www.greenbytes.de/tech/webdav/rfc4918.html#STATUS_422