# HTTP Methods

> The verbs (GET, POST, PUT, PATCH, DELETE) that indicate the desired action to be performed on a resource.

Subject: Internet | Lesson 10 of 35 | 3 min read
Interactive lesson: https://codewithanimation.in/internet/http-methods
Previous: [HTTP Response Anatomy](https://codewithanimation.in/internet/http-response-anatomy.md) | Next: [HTTP Status Codes](https://codewithanimation.in/internet/http-status-codes.md)

## What it is

**HTTP Methods** (or Verbs) indicate the desired action to be performed on a specific resource. The most common methods are **GET** (retrieve), **POST** (submit/create), **PUT** (replace), **PATCH** (partially modify), and **DELETE** (remove). Some methods are **Safe** (read-only, no state change) and some are **Idempotent** (doing it multiple times has the same end result as doing it once).

## Why it matters

Standardized verbs are the foundation of RESTful API design. Knowing which method corresponds to which CRUD operation ensures your APIs are predictable, maintainable, and cacheable by browsers.

## How it works

The HTTP method is the very first word in the request's start line (e.g., `POST /api/users HTTP/1.1`). Under the hood, functions like `fetch({ method: 'POST' })` simply build this starting string.

## Common mistake: Common mistake

Using POST for absolutely everything because 'it works' and can carry a payload, completely ignoring HTTP semantics. A close second is confusing PUT (which requires replacing the entire object) with PATCH (which modifies only specific fields).

## Tip: Pro tip

Map HTTP methods directly to database CRUD operations: **C**reate = POST, **R**ead = GET, **U**pdate = PUT/PATCH, **D**elete = DELETE.

## Try it: Try it

Test the Idempotency Vending Machine below to see how different HTTP methods affect the state of the server.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/internet/http-methods

## Check yourself

### Question 1

Which HTTP method should be used to retrieve user profile data without modifying it?

- A. GET
- B. POST
- C. PUT
- D. PATCH

Correct answer: A

GET is a 'safe' and idempotent method specifically designed to request and retrieve data without causing side effects.

- Why not B: POST is used to submit data and typically causes state changes on the server.
- Why not C: PUT replaces a resource with a new payload, heavily modifying server state.
- Why not D: PATCH is for applying partial modifications, not for reading data.

### Question 2

You need to update just the email address of an existing user profile, leaving all other fields intact. Which method is most semantically appropriate?

- A. PATCH
- B. PUT
- C. POST
- D. UPDATE

Correct answer: A

PATCH is specifically designed for applying partial modifications to an existing resource.

- Why not B: PUT replaces the entire resource, meaning you would have to send all profile fields again, not just the email.
- Why not C: POST is generally used for creating new resources, not targeted field updates of existing ones.
- Why not D: UPDATE is a SQL database command, not a valid HTTP request method.

### Question 3

What does it mean for an HTTP method to be 'idempotent'?

- A. Making the same request multiple times leaves the server in the exact same state as making it once.
- B. The method is strictly read-only and cannot alter the server state.
- C. The method encrypts the payload for secure transmission.
- D. The method is guaranteed to return a 200 OK status code.

Correct answer: A

Idempotency guarantees that whether you send the request once or ten times, the final state of the targeted resource remains identical (e.g., deleting an already deleted item still leaves it deleted).

- Why not B: This describes 'safe' methods. Some idempotent methods, like DELETE, do alter state.
- Why not C: Security is handled by HTTPS/TLS, not the idempotency of the HTTP method.
- Why not D: Idempotency refers to server state, not the response code, which could differ (e.g., 200 then 404) on repeat calls.

## Remember this

- GET is for retrieving data (Safe and Idempotent).
- POST is for creating new resources or submitting data (Not Safe, Not Idempotent).
- PUT replaces an entire resource (Idempotent), while PATCH updates partial fields.
- DELETE removes a resource (Idempotent).
