Search code examples
restasp.net-web-apiodata

Appropriate HTTP status code when accessing specific OData property without any value


What should be the correct HTTP status code returned when trying to access a specific property of an object when that property is null. I would think 404, but I can't see that the odata specification says anything about it.

GET api/MyObject(123)/MyProperty <-- this is null for this instance of the object

Should this return HTTP 404, empty object with HTTP 200, or something else?


Solution

  • It should return HTTP 204 No content, according to the OData V4 protocol:

    If the property is single-valued and has the null value, the service responds with 204 No Content. If the property is not available, for example due to permissions, the service responds with 404 Not Found.