HTTP basics – what do you need to know about it?

In this text, I’m going to cover all the basic information that every web developer should know about the most basic building block of the modern web, which is HTTP (in my humble opinion).

Due to its continuous popularity, I’m going to focus on HTTP/1.1 mostly.

Definition

HTTP (HyperText Transfer Protocol) is a protocol for transmitting hypertext documents. We use it to transfer data over the web.

Okay, but what the heck is hypertext? In short, it’s a text which contains a link to another text resource.  In contrary to that there’s a term called hypermedia which is used to describe other, non-text content types, like graphics, sound, videos, etc.

And last but not least, HTTP is the protocol of the application layer of the OSI model and it runs on the top of TCP protocol which is a transportation layer protocol and IP used for routing.

Historical background & the bright future

HTTP is widely used on the Internet since 1990. Version 1.1, although it was introduced in 1997, it still plays a major role on most of the websites nowadays.

A newer version of the protocol, HTTP/2 is adopted by nearly 50% of  the websites right now, and it’s still growing.

But don’t forget about the HTTP/3 which is the newest version of the protocol and is around for a while now. It’s already used by over 6% of the websites. So it’s not that bad when it comes to the adoption of the newer standards. The curve grows steadily.

Let’s take a look at the brief history of the protocol:

HTTP 0.9 (1991)

    • supports GET method only
    • runs on the top of the TCP
    • response type: HyperText
    • no response codes
    • no headers
    • works in request/response mode

HTTP 1.0 (1996)

    • supports GET, HEAD and POST methods
    • runs on the top of the TCP
    • response type: hypertext or scripts
    • headers introduction
    • works in request/response mode

HTTP 1.1 (1997)

    • still most commonly and widely used communication standard on the Internet
    • runs on the top of the TCP
    • additionally supports OPTIONS, PUT, DELETE, TRACE, CONNECT methods
    • response types: hypertext or scripts
    • headers support
    • introduced stream processing – you can send next request before you get the response for your first request

HTTP 2.0 (2015)

    • runs on the top of the SPDY, it’s a TCP-based Google-made protocol. It’s focused on speed and performance
    • runs in the persistent connection mode
    • allows for processing multiple requests at the same time

HTTP 3.0 (2018)

    • runs on the top of the QUIC, which is yet another Google protocol. But in contrary to SPDY, it’s UDP-based (because of the better performance and smaller latency)

Request & response

In simple words, HTTP works as a request-response protocol between client and server.

In your everyday use, you’ll send an HTTP request to the URL for a resource via your web browser, cURL, Postman, mobile app or another HTTP client.

In short: you’re the client and you expect the server to send a document in response. Usually, it’s an HTML document but it could be an image, a JSON or XML document, etc.)

Representation of the resource

The document that is sent by the server is called the representation of the resource.

We use a URL to identify the resource (one and only one). So when you, as a client, make an HTTP request to a URL, you don’t get the underlying resource directly, you always get only its representation.

Headers

HTTP headers are used for providing information about the request or the response or about the content object that is sent in the message body.

Let’s assume you’d like to do some shopping on the Amazon. The request headers your browser sends when you want to access the Amazon website could look more-or-less like this:

GET / HTTP/1.1
Host: www.amazon.com
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate, br
DNT: 1
Connection: keep-alive

The response headers from the Amazon server could look like this:

HTTP/2 200 OK
server: Server
content-type: text/html;charset=UTF-8
strict-transport-security: max-age=47474747; includeSubDomains; preload
vary: Accept-Encoding,User-Agent,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment
accept-ch: ect,rtt,downlink
accept-ch-lifetime: 86400
content-language: en-US
x-ua-compatible: IE=edge
cache-control: no-cache
pragma: no-cache
expires: -1
content-encoding: gzip
x-xss-protection: 1;
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
date: Tue, 09 Jun 2020 18:06:55 GMT

Looks like a lot of things are being sent back and forth, huh?

Don’t worry we’ll go through the most common of them in the next articles.

Methods

There are 8 methods in HTTP/1.1 protocol:

    • GET
    • HEAD
    • POST
    • PUT
    • DELETE
    • CONNECT
    • OPTIONS
    • TRACE

I bet at least some of them sound familiar to you. We’ll go through the most common of them in the next articles of this series. Believe me, they can be tricky 😉

Conclusion

There’s no doubt, there’s no web without HTTP. It’s bread and butter for every web developer.

Stay tuned for the updates from the Ad fontes articles series. We’re going to explore more of the HTTP details soon.

References

* Ad fontes – is a Latin term which means “to the sources

Leave a Reply

Your email address will not be published.