HTTP Basics

Gamze Yılan
Nerd For Tech
Published in
4 min readAug 25, 2021

Do you find requests and responses, methods and status codes confusing? Here’s an article to get things right in the simplest manner.

Short for Hyper Text Transfer Protocol, HTTP is a protocol that basically works as a language that is used for the communication between a server and a client. Everytime you visit a webpage, click a button or type in your e-mail to subscribe to a newsletter you’re using HTTP and going through a request & response cycle.

To make the communication more secure, we use HTTPS, which is basically what you get when you install a certificate to your web host. This certificate could be an SSL certificate or a TLS certificate. And what it does is that it basically encrypts these requests and responses between the client and the server. This is what gets you the warning sign or the lock sign by the side of your URL whenever you enter that said website.

Each request made to the server has a method attached to it. There are, in total, four methods that we use with our requests:

  1. GET: Retrieves data from server.
  2. POST: Submits data to the server.
  3. PUT: Updates the data that is already within the server.
  4. DELETE: Deletes the data that is already within the server.

Each request and response contain a header and a body.

Typically, the header holds three things: the request method, the path and the protocol that we’re using to send the request. The body, on the other hand, holds the data that is being communicated in between the server and the client using the path and method mentioned within the header. If you are, for example, asking the server for a website’s html&css, you are sending a GET request. What you get in response as the html&css is held within the body of that response. Or, if you’re sending a form you’ve filled to the server, you are sending a POST request and the information you’ve put within that form is held within the body of that request.

Each response from the server has a status code to inform us about how the request went. There are many codes, however, we can understand the basic structure to understand where the problem is when one occurs:

1xx: If your response gives you a status code that is one hundred and something, it means that the request is received and being processed right now.

2xx: If your response gives you a status code that is two hundred and something, it means that the request is successfully received, understood and accepted.

3xx: If your response gives you a status code that is three hundred and something, it means either that further action such as authorization or input must be taken or that it’s redirecting to another route.

4xx: If your response gives you a status code that is four hundred and something, it means that the request was somehow wrong or missing something.

5xx: If your response gives you a status code that is of five hundred and something, it means that although the request was healthy the server failed at giving the proper response.

Here are the most basic status codes:

  • 200: OK
  • 201: OK created (Something new is created)
  • 301: Moved to a New URL
  • 304: Not Modified (Cached Version)
  • 400: Bad Request
  • 401: Unauthorized
  • 404: Not Found
  • 500: Internal Server Error

To check what’s going on within a website, simply right click and select “Inspect”. Then, on the window that opens, select the Network tab. There you can see all the HTTP communication steps: request or response. The Status column holds the status codes. And if you double click on each response, you can see all about it from the headers (of request and response both) and the body to the timing in which the action was completed.

To send and receive requests from a URL, you can also use a tool called Postman. Used mostly by developers, Postman gives you a more advanced look on each request and comes in handy by helping you save requests or enter JSON data. To get started just click on New Request button after installation and select a method. Then, enter the URL that you’re going to send the request to and then, simply click on Send. Below, you can see the code or the Preview of the response or inspect Headers, Cookies, Response Status Code or even the size of the response.

Notice: When you use the put or post methods, you can enter the data that is to be sent via Postman. But keep in mind that within the headers, you need to specify the content type of the request you’re sending. If you’re sending JSON data for example, go to the Headers section under the request info and select Content:type as the key, then set the value to JSON. After that you can enter the JSON data into the body of the response under the Body tab.

--

--

Gamze Yılan
Nerd For Tech

Embark on my journey to becoming the world’s leading Software and Systems Engineer.