user1032531 user1032531 - 26 days ago 5
reST (reStructuredText) Question

Proper REST response if a requested field does not exist


is not set, I return all possible car fields. If an array is given for
, I return only those fields. For instance, the following query:

curl -X GET ''

should return a list of all cars
[{"name":"Ford", "color":"blue", "cost":10000},...]

Now, another request, but this time also includes the cars horsepower.

curl -X GET ''

But horsepower isn't supported by the application. Should I:

  • return only what is possible? ie
    [{"name":"Ford", "color":"blue", "cost":10000},...]

  • return all requested fields but include
    for unsupported fields ie
    [{"name":"Ford", "color":"blue", "cost":10000, "hp":null},...]

  • Don't return any results, but return an error?

  • Do something else?


I'd return an HTTP error code 400 Bad request along with an error JSON object such as {"error":"Unknown field: 'horsepower'"}, because you don't really know what the client wants to do. Perhaps they are requesting a non-existent field, or perhaps they've made a spelling mistake in one of the field.

If you silently ignore the error, it will be hard for the client to detect it. Better just return an error and let the client deal with it.