Blog about Web Programming and Electronics
💬 👤
back Back to blog
Programming

How HTTP Works (GET, POST, PUT, DELETE)

When we type a web address into the browser, a "conversation" takes place in the background between our computer and the server. This conversation follows the rules of the HTTP protocol — HyperText Transfer Protocol. Every request we send has its own method, which tells the server what we want to do. The four most important ones are GET, POST, PUT, and DELETE.

What is HTTP

HTTP is a protocol for transferring data between the client (the browser) and the server. It works on the request–response principle: the client sends a request, and the server returns a response. Every request contains a method, the resource address (URL), and possibly some data. The response contains a status code (e.g. 200 for success or 404 for a non-existent page) and the content.

GET /index.html HTTP/1.1
Host: vadnica.org

HTTP/1.1 200 OK
Content-Type: text/html

(page content ...)

GET: Reading Data

The GET method retrieves data from the server. It is used for visiting pages, loading images, searching the web — for everything we only read. GET does not modify data on the server, so it is safe to refresh such pages. The data we send (e.g. a search string) is sent directly in the URL address.

GET /search?q=http+tutorial HTTP/1.1
Host: vadnica.org

POST: Submitting Data

The POST method sends data to the server — most often from a form. When we enter a username and password and click Login, the browser sends a POST request with the data in the request body, which is not visible in the URL. POST typically creates new records or triggers processing on the server.

POST /login HTTP/1.1
Host: vadnica.org
Content-Type: application/x-www-form-urlencoded

username=name&password=secret

PUT: Updating Data

The PUT method updates existing data on the server. It is used mainly with APIs: if we want to change a user's data, we send a PUT request with the entire new content of the record. Unlike POST, which can create a new record each time, PUT always targets a specific resource and overwrites it.

PUT /users/42 HTTP/1.1
Host: vadnica.org
Content-Type: application/json

{"name": "Name", "email": "name@mail.com"}

DELETE: Deleting Data

The DELETE method sends the server a request to delete a specific resource. Like PUT, it is used mainly with APIs and always targets a specific resource, e.g. a single user or a single record.

DELETE /users/42 HTTP/1.1
Host: vadnica.org

Comparison of Methods

Method Purpose Example of use
GET Reading data Visiting a web page, searching
POST Submitting data, creating Login, registration, comment
PUT Updating data Changing a user profile
DELETE Deleting data Removing a record

HTTP in Practice

These four methods form the basis of so-called REST APIs, through which applications exchange data. We can imagine a library: GET means borrowing a book, POST adding a new book, PUT repairing an existing one, and DELETE removing one from the shelf. Every good API follows this logical division of tasks, so understanding the methods is crucial for every web developer.

All the communication an average user triggers every day — from opening a page to logging into an online bank — follows these rules. HTTP is the silent worker of the internet, effortlessly handling billions of requests per second.

back Back to blog