Return empty json on null in WebAPI

后端 未结 4 991
野性不改
野性不改 2021-02-04 02:50

Is it possible to return { } instead of null when webApi returns a null object? This, to prevent my user from getting errors while parsing the response. And to make the respon

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-04 03:32

    If you are building a RESTful service, and have nothing to return from the resource, I believe that it would be more correct to return 404 (Not Found) than a 200 (OK) response with an empty body.

提交回复
热议问题