So, if you look at the List of HTTP Status Codes, there are probably a number of them that would be useful while programming. The server might handle some things, like protocols
I take it your talking about using headers for either serving files or providing a RESTful webservice?
You'd be after status codes, rather than headers then. The ones I've commonly used are:
200 OK
301 Moved Permanently
302 Found (temporary redirect)
400 Bad Request
403 Forbidden
404 Not found
500 Internal Server Error
Of course, for RESTful webservices you can change the text to be more descriptive as well as providing description in the body.
Then there's:
418 I'm a teapot
Well, those are status codes, not headers, but any of them might be useful (although the 5xx series are unlikely to be).
The ones I've used most are:
To be more precise, these are just HTTP status codes, not HTTP headers. Headers convey a lot of things and are sent by both the client and the server, and are beyond the scope of this answer.
One of the HTTP headers, namely the first one sent by the server to the client, looks like this:
HTTP/1.x 200 OK
or:
HTTP/1.x 404 Not Found
The number that appears after the protocol identifier HTTP/1.x
is what's called the status code with the corresponding status message sent after it. Here are the status codes that I've had to use in my PHP programming days:
index.php
through while you route all requests using .htaccess or your Apache settings, Apache will almost never return a 404 on its own accord because, after all, it has found index.php
. But clearly, there will still be some URIs that you want to communicate don't lead to anywhere, for which you'll want to send your own 404 status header.Location
header and to redirect the user to the URL specified there. Most PHP frameworks have their own functions for HTTP redirects, which also handle the headers. The native PHP redirect header('Location: http://www.google.com');
automatically changes the HTTP status to 302. I've never really understood in depth the difference between 302 and 301, but I've read that 301 is much better for Search Engine Optimization, so I try to always use 301. Perhaps someone else can enlighten on what the exact difference is. One thing to be careful of is to avoid putting a 301/302 status and Location header on a page that's intended to receive POST data. I've had some trouble with it in the past.Quickly going through that list (of status codes), here are those I often use (I am doing PHP web-development as my job) :
And here are those I could use (especially if doing REST) :
Many of these are intrinsically useful with REST-style API usage. For example:
200 (OK): You asked for a resource. Here it is!
201 (Created): You asked me to make a new resource. I did! Here's where you can go to ask me for it next time.
202 (Accepted): You asked me to do something, but it's going to take a while, so don't wait up. Here's where you can go to check up on the status.
300 (Multiple Choices): You asked for something, but you weren't specific enough. Which one of these did you mean?
301 (Moved Permanently): You asked for something, but it's somewhere else now. Here's where it went.
302 (Found): You asked for something, but it's somewhere else for the moment. Here it is.
304 (Not Modified): You asked for something before this, but it hasn't changed since the last time you asked me.
400 (Bad Request): Something is wrong about what you asked me to do. Fix what you said and try again.
401 (Unauthorized): I need you to identify yourself before I can finish this request. [Note: This is one of the more unfortunately named headers. It should really be titled Unauthenticated; 403 is more like Unauthorized.]
403 (Forbidden): You asked for something you're not allowed to have.
404 (Not Found): You asked for a resource, but there isn't one that matches your description.
500 (Server Error): Something went wrong, so I can't give you what you asked for right now. Sorry about that.
501 (Not Implemented): I don't support that kind of request right now.
503 (Service Unavailable): I'm not able to respond to requests right now.