Which http status code returns, 404 or 422?

http, rest, ruby-on-rails

Solution

I'll change my answer to `422` because you couldn't finish processing the request. Unprocessable entity its a better match, you didn't request an object so "not found" doesn't make a lot of sense. At the end is your choice, just choose whatever feels better to you.

422 Unprocessable Entity (WebDAV; RFC 4918) The request was well-formed but was unable to be followed due to semantic errors

Source: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error

Problem

I have a Rails API application with the next resource: `/images`. All images have one `owner`. To create a new image, I do next request to /images: ``` image_info = { owner_id: '1234', name: 'img1' } post :create, :format => "json", :image => @image_info ``` In controller of images I do: ``` owner = User.find( params[:owner_id] ) ``` If `owner_id` don't exists or is invalid, what error code should the backend return, 404 or 422 with `owner_id: invalid`?

Original source