我有一个 API 可以让你销毁一个对象。我不确定的部分是记录被销毁后应该呈现什么 JSON。这里有几个选项,但我不确定最佳实践是什么。
版本 1:
返回具有 204 状态的空对象
def destroy
item = current_user.current_cart.items.find(params[:id])
item.destroy
render json: {}, status: :no_content
end
版本 2:
归还物品,即使它已被销毁
def destroy
item = current_user.current_cart.items.find(params[:id])
item.destroy
render json: item
end
其中一个是否优于另一个?有没有我没有想到的可能是首选的版本?