400 vs 422 response to POST that references an unknown entity

后端 未结 5 2028
面向向阳花
面向向阳花 2020-12-30 11:24

I\'m trying to figure out what the correct status code to return on different scenarios with a \"rest-like\" API that I\'m working on.

This example is borrowed from

5条回答
  •  粉色の甜心
    2020-12-30 12:05

    I'd say 422 is adequate in your case, but 400 isn't bad if it's consistent with the rest of your API. It's a common convention to use 400 as an umbrella error code when there's something wrong on the client side, but either the error doesn't fit a particular error code, or you don't want to use too many of them.

    A 404 is definitely wrong if there's something wrong with the POST payload.

提交回复
热议问题