HTTP is Hyper Text Transfer Protocol which involves protocols involving communication between web servers and clients. It can be thought as the messenger of the web. Client is the one who makes the request(HTTP Message) and the server responds(HTTP Message) to that request.
HTTP is state-less i.e. it doesn't remember anything about the previous page when we go from one webpage to another(Cookies and Sessions are additional stuffs, and aren't part of HTTP core). Each request can be thought of as a single transaction.
HTTP is connection-less i.e. there is no fixed 24*7 connection between the client and the server, rather the connection happens with each request and response cycle. For further requests, there will be more new connections.
A HTTP Message has 3 parts:
Start line, Headers and Body. The message body is optional
The info present in the 3 section varies depending if that is a request or a response.
For Request:
startline has the method name telling the server what to do, URL and the version number.
Headers can be thought as a few key-value pairs like host, accept-language etc.
A message body is the one which carries actual HTTP request data (including form data and uploaded etc.)
For Response:
No method is required in the startline of a response. However it contains the http version and the status code.
A message body may contain HTTP response data from the server ( including files, images etc)
Some methods used in HTTP:
Method is a command instructing the server what to do.Method names are always in uppercase.
GET: Every time we visit a webpage, we make a GET request to the server via HTTP.
POST: When adding some data to the server like - submitting a form,creating a blog post, uploading an image. In a POST request, we send data to the server which is then stored in a database.
PUT: PUT request is used to update some already existing data.
DELETE: DELETE request deletes data from the server.
Each Request and Response has a header and a body.
The Response body is the html or json or whatever is being sent from the server end.
HTTP STATUS CODES:
As the name refers to, these are codes referring to different statuses.
It has a range from 100 to 500.
1XX : Informational
Request received/processing.
2XX : Success
Successfully received, understood and accepted.
3XX : Redirect
Further action/Redirect.
4XX : Client Error
Request doesn't have what it needs.
5XX : Server Error
Server couldn't fulfill some valid request.
Top comments (2)
This is a pretty great write up on a very fundamental concept.
Thanks :)