# Understanding HTTP Methods: GET, POST, PUT & DELETE Explained with Examples

### 📌 Introduction

Every time you open a website, submit a form, or use a mobile app, there’s a silent conversation happening between the client (browser/app) and the server. This communication is powered by HTTP (HyperText Transfer Protocol), and at the heart of it are **HTTP methods**.

As a backend developer—especially in Java with frameworks like Spring Boot—understanding these methods is not optional. They define **how data flows**, **what action is being requested**, and **how APIs behave**.

In this article, we’ll break down the four most important HTTP methods—**GET, POST, PUT, and DELETE**—with clear explanations, real-world examples, and best practices.

### 🌐 What Are HTTP Methods?

HTTP methods (also called verbs) indicate the **type of action** the client wants to perform on a resource.

A *resource* could be:

*   A user
    
*   A product
    
*   A database record
    
*   Any data exposed via an API
    

Think of HTTP methods like CRUD operations:

| Operation | HTTP Method |
| --- | --- |
| Create | POST |
| Read | GET |
| Update | PUT |
| Delete | DELETE |

![](https://cdn.hashnode.com/uploads/covers/68ff77d16e456bcb7f896110/e9399d71-245a-4959-8109-1f74fa4f492f.png align="center")

## 📥 GET Method – Retrieving Data

The **GET** method is used to **fetch data from the server**.

### ✅ Key Characteristics:

*   Does **not modify data**
    
*   Parameters are sent via URL
    
*   Can be cached
    
*   Safe and idempotent
    

### 📌 Example:

```plaintext
GET /api/users/1
```

This request retrieves the user with ID = 1.

### 💡 Java (Spring Boot Example):

```plaintext
@GetMapping("/users/{id}")
public User getUser(@PathVariable Long id) {
    return userService.findById(id);
}
```

### ⚠️ When to Use:

*   Fetching user data
    
*   Loading web pages
    
*   Querying lists or records
    

## 📤 POST Method – Sending Data

The **POST** method is used to **create a new resource** on the server.

### ✅ Key Characteristics:

*   Modifies server state
    
*   Data is sent in the request body
    
*   Not idempotent (multiple calls create multiple resources)
    

### 📌 Example:

```plaintext
POST /api/users
```

Request Body:

```plaintext
{
  "name": "Paul",
  "email": "paul@example.com"
}
```

### 💡 Java (Spring Boot Example):

```plaintext
@PostMapping("/users")
public User createUser(@RequestBody User user) {
    return userService.save(user);
}
```

### ⚠️ When to Use:

*   Registering a user
    
*   Submitting forms
    
*   Creating new records
    

![](https://cdn.hashnode.com/uploads/covers/68ff77d16e456bcb7f896110/a7d6ab22-7964-407a-b518-dcc2175e38d7.png align="center")

## 🔄 PUT Method – Updating Data

The **PUT** method is used to **update an existing resource**.

### ✅ Key Characteristics:

*   Replaces the entire resource
    
*   Idempotent (same request → same result)
    

### 📌 Example:

```plaintext
PUT /api/users/1
```

Request Body:

```plaintext
{
  "name": "Paul Samuel",
  "email": "paul_new@example.com"
}
```

### 💡 Java (Spring Boot Example):

```plaintext
@PutMapping("/users/{id}")
public User updateUser(@PathVariable Long id, @RequestBody User user) {
    return userService.update(id, user);
}
```

### ⚠️ When to Use:

*   Updating full user profile
    
*   Replacing existing data
    

## ❌ DELETE Method – Removing Data

The **DELETE** method is used to **remove a resource** from the server.

### ✅ Key Characteristics:

*   Deletes data
    
*   Idempotent (deleting again won’t change result)
    

### 📌 Example:

```plaintext
DELETE /api/users/1
```

### 💡 Java (Spring Boot Example):

```plaintext
@DeleteMapping("/users/{id}")
public void deleteUser(@PathVariable Long id) {
    userService.delete(id);
}
```

### ⚠️ When to Use:

*   Deleting user accounts
    
*   Removing records
    

## ⚖️ Key Differences at a Glance

| Method | Purpose | Idempotent | Request Body | Safe |
| --- | --- | --- | --- | --- |
| GET | Read | ✅ Yes | ❌ No | ✅ Yes |
| POST | Create | ❌ No | ✅ Yes | ❌ No |
| PUT | Update | ✅ Yes | ✅ Yes | ❌ No |
| DELETE | Delete | ✅ Yes | ❌ Usually | ❌ No |

## 🧠 Idempotency & Safety (Important Concept)

Two critical concepts every backend developer must understand:

### 🔁 Idempotent

An operation is **idempotent** if performing it multiple times produces the same result.

*   PUT → updating same data repeatedly doesn’t change outcome
    
*   DELETE → deleting an already deleted resource has no effect
    

### 🛡️ Safe Methods

Safe methods do **not modify data**.

*   GET is safe
    
*   POST, PUT, DELETE are not
    

![](https://cdn.hashnode.com/uploads/covers/68ff77d16e456bcb7f896110/965297b7-3513-4ab8-b4d6-e95ab2cdba93.png align="center")

## 🛠️ Real-World API Example

Let’s take a simple **User Management API**:

| Action | Method | Endpoint |
| --- | --- | --- |
| Get all users | GET | /users |
| Get user by ID | GET | /users/{id} |
| Create user | POST | /users |
| Update user | PUT | /users/{id} |
| Delete user | DELETE | /users/{id} |

This structure follows **RESTful principles**, which are widely used in modern backend development.

* * *

## 🔐 Security Considerations

*   Always use **HTTPS** to encrypt data
    
*   Avoid sending sensitive data in GET URLs
    
*   Validate request bodies in POST/PUT
    
*   Implement authentication (JWT, OAuth)
    

* * *

## 🚀 Best Practices for Using HTTP Methods

✔ Use the correct method for the correct operation

✔ Follow REST conventions

✔ Keep APIs predictable and consistent

✔ Avoid using POST for everything (common beginner mistake)

✔ Handle errors properly (404, 500, etc.)

* * *

## 📚 Conclusion

HTTP methods are the **foundation of backend development and API design**. Whether you're building a simple CRUD application or a scalable microservice architecture, mastering GET, POST, PUT, and DELETE is essential.

As a Java backend developer, especially with Spring Boot, these methods directly map to your controller logic. The better you understand them, the cleaner, more scalable, and more professional your APIs will be.

> If you truly want to become a strong backend developer, don’t just use HTTP methods—**understand their intent and design your APIs accordingly.**
