HTTP Status Codes for My Fellow Web Developers

Today I have reviewing some of my projects and found that I was designing some application without awaring http status codes. You might want to ask me that what exactly Http Status Code is and do we need to know about it ? I say yes.

HTTP 1.1

We are using a protocol called HTTP to transfer documents from one network client to others on Internet. We request resources like web pages from others computers like web servers as a client and receive the requested resources with status codes in header.

Lets see in action. Open your terminal.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ curl -i http://google.com.mm
HTTP/1.1 200 OK
Date: Thu, 17 Apr 2014 12:46:24 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=UTF-8
Set-Cookie: PREF=ID=66d9847d27923e40:FF=0:TM=1397738784:LM=1397738784:S=LiYjsqS5DyfmVSm0; expires=Sat, 16-Apr-2016 12:46:24 GMT; path=/; domain=.google.com.mm
Set-Cookie: NID=67=KcMe4sI0J3A3jhv_OvHTIcIA_ggl9-2rg1PNmKk9idqQNCpKC7knl64EDL9UZ8N4vlhf6Cc-y2o3wrQ0aVj3l3FbaxZpfWxX_1yZWWADBXvVCao1yFV-8-DJB1ysLMcS; expires=Fri, 17-Oct-2014 12:46:24 GMT; path=/; domain=.google.com.mm; HttpOnly
P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alternate-Protocol: 80:quic
Transfer-Encoding: chunked

This is a little tricky. If you do the curl to http://google.com and will be redirected to google.com.mm if you are living in Myanmar. So the best way is just to go straight to http://google.com.mm !

You can see the response comes with the header as 200 OK. This means requested resource is found and return as expected.

There are a few of these codes you should know by heart as a web developer.

2xx SUCCESS

200 : Standard response for successful HTTP requests

3xx Redirection

302 : Temporary response to request found via alternative URI [If you have done curl to http://google.com , you might get this response coz it is redirected towards google.com.mm]

304 : Resource has not been modified since last requested [Most of the assets like css,js and images would be returned as 304 then the browser will use the local cache instead of getting new ones from server.]

4xx client error

404 : Requested resource you send is not found on server [ It is your fault , check your request again]

444 : Server returns no information and closes the connection

5xx Server Error

500 : Generic Error [ Something is wrong within the server ]

503 : Server is currently unavaiable [ In other words , Server is down ]

504 : Gateway did not receive response from upstream server [ If you are sending your request via a proxy , upstream server is not giving back anything to your proxy server ]

Ok , this might be enough for most of us. Anyone who want further learning about HTTP Status Codes , here is a good place.

Copyright © 2016 - Tin Aung Linn. Powered by Octopress