What Is HTTP?

Arvin Fernandez
3 min readAug 5, 2021

I feel HTTP is a topic that is not mentioned as much as it should be in the programming world. Regardless of whether you work in the backend or frontend its important that you understand how HTTP works. This post will be discussing what HTTP is, how it works, the request/response cycle, header/body and status codes. Just enough to get you comfortable when asked any questions about the subject.

What Is HTTP?

HTTP stands for Hyper Text Transfer Protocol. It is basically responsible for the communication between servers and clients in the web.

Every time you open up your browser, send a post, or make some sort of AJAX call you are using HTTP through something called the request and response cycle which is how HTTP works. The client, usually the browser, sends a request to the server which then returns a response.

HTTP Is Stateless

In the web, every request is completely independent. The browser/server doesn’t remember anything from the last request you’ve made. Because of this we have other things like local storage, sessions and cookies to make the web more user friendly. Without this we would have to sign into our amazon account every time we refresh or return to the page.

HTTPS

HTTPS is the same as HTTP with the only difference being that HTTPS encrypts the data being sent back and forth using SSL.

Any situation which consists of users sending sensitive information such as passwords or credit card information should be sent using HTTPS. Most websites nowadays are forcing HTTPS on every page. Which can be implemented by installing an SSL certificate on your web host.

HTTP Methods(verbs)

When a request is made to a server there is always a method attached to it. This information is used in conjunction with the URL to determine what the request is trying to do to the resource.

There are a bunch of HTTP methods but the most common ones are:

  • GET: This method is used whenever we are trying to get data from the server. Every time you visit a webpage you are making a GET request via HTTP. Examples include loading an HTML page or hitting an API which returns JSON
  • POST: These requests are usually made when trying to create something on the server. Whenever we fill out a form and hit submit we are making a POST request to the server. Its possible to send forms via GET but it’s not recommended because the data being sent would appear in the URL.
  • PUT: Whenever we need to update data that already exists on the server. For example, editing your profile on Facebook.
  • DELETE: This method simply deletes data from the server.

Header Fields

With each request/response using HTTP there is something called a header and something called a body.

Typically with a the body in a response would be the HTML page which will be rendered or the form data in a POST request.

In the header is where the metadata such as cookies, authorization tokens, and status codes are sent through. They are divided into 3 categories which are: general, response and request headers. Check the docs for more header fields information.

Status Codes

Whenever a request is made the response would include a status code representing the status of the request made. They are represented by a range 3 digit numbers and are categorized by the range that they are in. For example:

  • 100–199: Informational — these mean that the request has been received and is being processed.
  • 200–299: Success — means that everything went as expected.
  • 300–399: Redirect — means redirection or that further action must be taken.
  • 400–499: Client Error — means that the server didn’t receive all the information it needs from the client.
  • 500–599: Server Error — when the server fails to fulfill a request.

These are some of the most common codes and their meanings:

  • Code 200 — OK.
  • Code 301 — Permanent Redirect.
  • Code 302 — Temporary Redirect.
  • Code 404 — Not Found.
  • Code 410 — Gone.
  • Code 500 — Internal Server Error.
  • Code 503 — Service Unavailable.

Conclusion

Understanding HTTP is necessary when developing web apps and understanding how they work. Anything that requires communication between servers requires you follow this protocol. You can go much more in depth on this subject but this should be enough to get you going making some requests.

--

--

Arvin Fernandez

Junior Developer trying to help other developers(and myself) better understand programming.