Take a hypothetical camera company providing an API to manage its users and cameras. Each user owns cameras, and every user of a camera has a role assigned (one of admin, operator, viewer - these are defined in a database, and we might add new roles later).
If I have a GET request that fetches details of a camera using a parameter in the URL itself, for example:
www.cameracompany.com/camera/{id}
should return 404
when you enter an ID that doesn't exist - because you're hitting a URL that doesn't exist.
Question 1:
However, say we were hypothetically doing the same with a POST request (lord forbid we ever do) to www.cameracompany.com/camera
and send {id} as a form parameter. Should it return 404
or 400
?
I argue 400
because the URL exists, but the parameter data entered is wrong but I had a pretty heated argument where my colleague is convinced it should be 404.
Question 2:
To take a more concrete example, let's say we're trying to update the role of a user from admin to operator. The API endpoint is a PUT
request to www.cameracompany.com/camera/user/
where you enter camera_id
, user_id
, and role
. Say you enter valid camera and user IDs, but jargon for the role, what status code should the API return?
My understanding is:
404
when a URL doesn't exist.400
when insufficient parameters are sent in a PUT/POST request. But should400
also be sent when the number & names of parameters are right, but the data contained in them is illegal?
www.cameracompany.com/camera
and it DOES exist.