If, for example, no record is found do you return a 404 status code or a 200 with an error message?
I'm partial to using HTTP status codes and was wondering what the HN consensus was.
The answer is either way, and it depends on the tooling you are using. If you are relying on a client library that doesn't handle HTTP errors in the way you want, then you return a 200 - OK {"error": "bad request"}. If the client library does what you want, then returning a limited selection of 4xx errors is very useful for letting the client know what happened quickly and easily.
Personally, I default to using the HTTP error codes. But I know that some really large companies don't agree, and always return a 200 OK to any valid request.
(1) asked for a resource which does not exist - 404
(2) does not have permission to access the resource - 403
(3) is not authenticated - 401
(4) not correct / enough parameters provided - bad request 400.
(5) doing a post request where a put request was supposed to be made - 405
5xx is when the server is doing something wrong. Most common is whenever something unexpected has happened - 500 Internal Server Error
this policy is essential when bug hunting: if you get a 404, you should be certain its an http issue, not a db one