The Internet has surrounded us for a long time now, and even household appliances are connected to it, yet for many people the basic concepts behind connecting to the world remain unknown. I would even say the problem is growing: the web is so common that some people forget (as the outages of 2021 showed) that it is what social networks and all our other favorite websites run on. And yes, the Internet is not the same thing as the World Wide Web. Today we will write mainly about the latter.

So here is another article about the basics of this field, and I believe it will be useful to many people, both non-IT readers who are curious about the world and those who are just starting out in serious IT. Today we will describe in general terms what HTTP requests are and what kinds there are. Before we get to the requests themselves, though, we need to explain another, even more basic matter.

What is HTTP and how does it differ from HTTPS?

HTTP (or Hypertext Transfer Protocol) is the protocol the World Wide Web uses to transfer information about pages or, more generally, web resources. Put briefly and a little simply: to reach anything on the web, we have to use HTTP, and that is what web browsers (such as Google Chrome, Mozilla Firefox or Safari) are for. The default port (a kind of "entrance gate" where communication is possible) is 80.

It is a protocol based on requests and responses. Requests are sent from the user to the server hosting the page, and they usually consist of:

  • a URL (the web address where a resource, such as a page or an image, is located)
  • parameters or the content (body) of the request
  • headers

The response, in turn, is sent from the server back to the user who asked, and it contains:

  • a status code (if everything is fine, it is between 200 and 299)
  • the resource itself (for example, the content of a web page)
  • headers

Web browsers exist precisely to send these requests properly and to interpret what servers return, so that in the end the data the user wanted is displayed. REST APIs are also built on HTTP, and this is how we can fetch data in text form.

If we add "Secure" to the expansion of Hypertext Transfer Protocol, we get HTTPS, which is simply HTTP with encrypted communication, running on port 443 by default. Today it is practically essential if we want to be taken seriously by users, customers and even search engines (such as Google). Of course, sites running on plain HTTP still exist, but they serve internal purposes, or they are test versions, or they simply do not present valuable information that we would want to encrypt. Even so, it is worth aiming for HTTPS on every site published on the web, and in some places it is even required. The padlock we can see next to a website's address is also tied to this protocol.

Encryption itself is a much broader subject and we will not cover it today, but I will mention that to offer an encrypted version, the server must have a certificate installed. There are three kinds:

  1. A "homemade" certificate that you generate yourself. This is usually the one that makes the browser first ask whether we really want to visit an "unsafe site".
  2. A Let's Encrypt certificate, managed by an organization that provides free certificates of this type. It is a thoroughly trusted provider, though it may not be enough for some, especially for sites that must put security first (for example, fintech).
  3. A certificate from a trust service provider. This is the highest level of initiation, giving us certificates signed by a respected institution. As you can probably guess, it is not free.

For most sites, a certificate generated with Let's Encrypt is definitely enough, especially if we have console access to the server and know how a server differs from a domain.

Is HTTP the same as HTML?

No. HTTP is a protocol, while HTML (Hypertext Markup Language) is a markup language built from elements (also known as tags) that describes a web page. It is exactly what is sent as the content of a page and what the browser interprets in order to display the site the way its authors designed it. Interestingly, anyone can look at the source of such a page: just right-click (even while reading this text) and choose "Inspect element" or "Inspect" (depending on the browser).

Of course, it is not quite that simple. HTML can hold a lot of information, and not all of it is meant for displaying data properly. Some of it is meant for search engines, for example. There are also dynamically loaded pages, which add further elements of the site along the way using scripts written in JavaScript. Still, everything rests on good old tags, their attributes and the content they carry.

The most popular request types: GET and POST

These are two types of HTTP requests (or rather methods) that we deal with every day while browsing the Internet. Every one of us does, whether we are programmers or ordinary users scrolling through a Facebook wall.

The GET method is usually used to retrieve data. So it is the plain request of a user to display a web page: we type in a web address, the browser makes a GET request under the hood, and in response we receive HTML. It is the most basic type of HTTP request, and it usually puts the parameters for displaying the page in the address itself. Let us look at an example from this very blog:

https://wildasoftware.pl/blog?categories=feedybacky&page=1

What we see in the address after the question mark are the request parameters. They are additional information attached to the address (here "https://wildasoftware.pl/blog"), which narrows down what the user wants to get. Consecutive parameters are separated by ampersands (&). This structure is used, among other things, for filtering data, which makes it possible to copy the address and use it later with the conditions already set.

So GET is most often used to retrieve data. You can guess, then, that POST lets us send information to the server in order to save it, and that is indeed how it is most often used. But keep in mind that this is more of a convention: if someone wants to, they can also save data with GET and retrieve it with POST. One reason to stick to the convention is security. Why?

POST does not send parameters in the URL, where they could, for example, be remembered by the browser and suggested from history. Here the arguments make up the body of the request, which does not appear explicitly in the address but is attached to it "in the background". You can still inspect it in the browser without trouble, but it is a little harder than with GET requests. It also makes it harder to recover submitted values from the history, which matters, for example, when securing login operations on websites.

In fact, GET can also send data in the request body, and POST can use parameters in the URL. But these request types are separated for a reason. They also hide a few more secrets (POST especially), but to avoid confusing you further, we will stop here.

Other HTTP methods

GET and POST are not the only HTTP methods available. The spread of REST services also brought wider use of, for example, PUT and DELETE.

The former is similar to POST and also lets you send data in the request body, but it has differences too, including one of convention: POST is usually used to create data and PUT to update it. Or the other way round, because there are two conventions that swap the meaning of these two methods, and in the end it is usually up to the IT team what a given request type will be used for.

DELETE, in turn, usually does what its name says: it deletes data. Interestingly, it is fairly closely "related" to GET, because it also has its parameters directly in the URL, so the use of DELETE should be strictly controlled by the web application with regard to permissions.

That is not the end of HTTP methods, because there are a few more:

  • HEAD: retrieves only information about a resource, not its content. Interestingly, it can be used when attacking a site.
  • OPTIONS: retrieves information about whether a method is available and what it requires. It is usually used when checking so-called CORS (which we will get to explain some day).
  • TRACE: connection diagnostics.
  • CONNECT: a request for tunneling and proxy servers.
  • PATCH: updating only a part of the information.

These methods are rarely used "explicitly", though, and of those above only HEAD and OPTIONS are fairly common in web applications. Still, it is worth knowing they exist, because they make it easier, for example, to analyze communication when trying to find problems on a site or in a connection.

Summary

This article was not meant to cover the HTTP standard and its methods in full, only to introduce them to people who are just starting to learn about Internet resources on purpose. I hope that after reading it, terms such as GET and POST will no longer be black magic for you, and that the padlock icon next to HTTPS will stop being merely decorative.

Best regards, and thank you. Jakub Rojek.