Self-paced

Explore our extensive collection of courses designed to help you master various subjects and skills. Whether you're a beginner or an advanced learner, there's something here for everyone.

Bootcamp

Learn live

Join us for our free workshops, webinars, and other events to learn more about our programs and get started on your journey to becoming a developer.

Upcoming live events

Learning library

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

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

Full-Stack Software Developer - 16w

Data Science and Machine Learning - 16 wks

Search from all Lessons


LoginGet Started
← Back to Lessons

Weekly Coding Challenge

Every week, we pick a real-life project to build your portfolio and get ready for a job. All projects are built with ChatGPT as co-pilot!

Start the Challenge

Podcast: Code Sets You Free

A tech-culture podcast where you learn to fight the enemies that blocks your way to become a successful professional in tech.

Listen the podcast
  • HTTP

Edit on Github

What is HTTP?

What is HTTP?

What is HTTP?

HTTP (HyperText Transfer Protocol) is a protocol used to transmit hypermedia documents over the Web. It is involved in all information transmission flows across the Internet.

This protocol operates between a client and a server. Thus, the client makes a request by sending a message in a certain format to the server. The server then returns with a text response.

This communication, as shown in the following gif, is carried out through a process:

  1. The client wants to send an image through a server. The server receives the image and transforms it into text. This text is unreadable by humans. If a hacker were to intercept this, what he would see is a set of symbols/letters/numbers one after the other.
  2. The image is transformed into text and then transmitted over the Internet.
  3. The string of characters arrives at the receiver's computer/mobile device, in this case, the grandmother.
  4. When the grandmother receives the file and wants to open it, decoding is carried out, which transforms the text into an image for subsequent viewing.

Sending an image through the Internet

Image 1: The 4 steps necessary to send images over the Internet: decoding the image, transmission, reception and decoding... Finally, the grandmother feels happy after seeing her granddaughter's picture!

How does HTTP work?

HTTP diagram

The HTTP protocol works through requests and responses from the client (e.g., a web browser) and a server (e.g., the computers that host and display websites).

The server, after receiving a request, responds with a structured message 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, user) that specifies the document it requests and the method it applies. The client sends this request to a server, and then waits for the response.

A request to get a web page, in this case, google.com, in HTTP language would look something like this:

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

In this particular case we are using the GET method because we want to get/receive a resource.

This simple message communicates everything we need to know 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:
MethodDescription
GETRequests a representation of the specified resource. Used to request a resource from a server.
POSTSends information to the server. This information, depending on the server and the context, can be used, for example, to add records to a database, add information to a user profile on a website, and so on.
PUTSends information to the server, but unlike POST, this method is used to update information already on the server.
DELETEUsed to delete data on the server.
1DELETE /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 in the request that the server will receive.

Every response from a server will carry with it a response code or status code. Some of the most common ones are listed below.

Response codes

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 request method used).

Translated into HTTP, the response would look something like this:

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

The response contains the requested resource as well as the response code. In this case, 200 indicates that everything is correct, that the resource has been received, and that the communication was successful.

HTTP status codes can be found here, and depending on the number they start with, they provide very valuable information:

  • 1xx - Metadata
  • 2xx - All OK
  • 3xx - Redirection
  • 4xx - Client did something wrong
  • 5xx - Server did something wrong