4Geeks logo
4Geeks logo
About us

Learning library

For all the self-taught geeks out there, here our content library with most of the learning materials we have produces throughout the years.

It makes sense to start learning by reading and watching videos about fundamentals and how things work.

Full-Stack Software Developer

Data Science and Machine Learning - 16 wks

Search from all Lessons

Social & live learning

The most efficient way to learn: Join a cohort with classmates just like you, live streams, impromptu coding sessions, live tutorials with real experts, and stay motivated.

← Back to Lessons

Continue learning for free about:

Edit on Github

What is HTTP?

What is HTTP?

What is HTTP?

HTTP stands for Hypertext Transfer Protocol. It is a set of communication rules that enables the flow of information over the World Wide Web (WWW).

Basically, it is protocol to transfer text that operates through requests between a client and a server. HTTP is the term used to describe this simple text-based language. No matter how it is developed, the server's goal will always be to understand and return plain text responses.

what is http?

How does HTTP work?

This protocol works through requests and responses from the client (e.g., a web browser) and a server (e.g., the computers on which web sites reside).

The server responds with a structured response and a series of metadata that establishes guidelines for the initiation, development and closure of the communication. These guidelines are called "request methods".

A sequence of these requests is known as an HTTP session.

Request methods

Every conversation on the web starts with a request. This request is a text message or a set of lines created by a client (browser, app) that specifies the document you are requesting and the method you will apply. The client sends this request to a server, and then awaits for the response.

A request in HTTP language would be something like this:

1 2GET / HTTP/1.1 3Host: google.com 4Accept: text/html 5User-Agent: Chrome/31.0.1650.57 (Macintosh; Intel Mac OS X 10_9_0)

In this particular case we are using the GET method.

This simple message communicates everything necessary about exactly what resource the client is requesting. The first line of an HTTP request is the most important and contains two things:

  • the URI (Uniform Resource Identifier) which is the unique address or location that identifies the resource the client wants.
  • the HTTP method defines what you want to do with the resource and is your request method. The most commonly used are the following:
GETIt is used to read the server status. Being a safe operation, it can be executed several times without risk of data modification or corruption; calling it once has the same effect as calling it ten times.
POSTREST purists use post only for creation. That means that every time you POST something to an API, you are creating a new record in the database for it. Some APIs use POST for all write operations (delete, update and create). They do this because PUT and DELETE are not available in HTML / Forms and that makes those methods more difficult to use.
PUTThis is most commonly used to update state on the server; although it can also be used to create state.
DELETEThis is used for deleting data on the server.
1 2DELETE /blog/15 HTTP/1.1

In addition to the first line, an HTTP request also has other lines of data called request headers, through which it can deliver a wide range of information such as: the name of the server or host, the response formats that the client accepts to make the request, the format in which it is sending data in the body of the request (if applicable)...

Status Codes for the Response

When the server receives the request, it knows exactly what resource the client needs (through the URI) and what it wants to do with that resource (through the HTTP method).

Translated to HTTP the response would be something like this:

1 2HTTP/1.1 200 OK 3Date: Sun, 01 Dec 2013 18:17:45 GMT 4Server: Apache/2.2.22 (Ubuntu) 5Content-Type: text/html

The response contains the requested resource. The first line is very important and contains the status of the response. In this case it is 200, i.e. everything is OK.

HTTP status codes, you can read more about it here, provide metadata in the response to the status of the requested resources. They are part of what makes the Web a platform to build distributed systems. They fall into the following categories:

  • 1xx - Metadata.
  • 2xx - Everything is ok.
  • 3xx - Redirection
  • 4xx - Client did something wrong
  • 5xx - Server did something wrong