Is there any difference between the Ok() method new ObjectResult()?

后端 未结 3 574
悲&欢浪女
悲&欢浪女 2021-01-01 09:21

Scenario: implementing a standard REST API / GET method on a .net core controller.

The documentation states that OkObjectResult is an ObjectResult with status 200. T

3条回答
  •  悲&欢浪女
    2021-01-01 09:33

    I can only see the difference in relying on some default value somewhere and providing this value explicitly - the latter is usually better and your intention is much more clear with OkObjectResult (or setting StatusCode explicitly), which is important enough. ObjectResult does not have default StatusCode of 200 - it actually have this value null by default. However, HttpResponse has default status code 200, so it works the same anyway.

提交回复
热议问题