REST API Methods Explained: GET, POST, PUT, PATCH, DELETE
What each REST API method does, with a to-do list example, typical status codes, PUT vs PATCH, and what safe and idempotent mean.
Short answer: REST API methods tell the server what you want to do with a resource. GET reads, POST creates, PUT replaces, PATCH updates part of it, and DELETE removes it. Using them consistently makes an API predictable for everyone who calls it.
The Idea: Resource plus Method
A REST API names things with URLs, such as /todos for a to-do list and /todos/7 for one item. The HTTP method says the action. The same URL can mean different things depending on the method.
Each Method with an Example
GET: read
GET /todos/7 returns that to-do, with no body sent. Typical status: 200 OK (or 404 Not Found if it does not exist).
POST: create
POST /todos with body {"title": "Buy milk", "done": false} creates a new to-do, and the server picks its id. Typical status: 201 Created.
PUT: replace
PUT /todos/7 with body {"title": "Buy oat milk", "done": true} replaces the whole to-do with what you send. Typical status: 200 OK or 204 No Content.
PATCH: update part
PATCH /todos/7 with body {"done": true} changes only the done field and leaves the rest alone. Typical status: 200 OK.
DELETE: remove
DELETE /todos/7 removes the item. Typical status: 204 No Content.
PUT vs PATCH
Say a to-do is {"title": "Buy milk", "done": false}.
PUT with
{"done": true}means “this is the whole new to-do”. A strict API may reject it or erasetitle, because you did not send it.PATCH with
{"done": true}means “change just this field”. The title stays “Buy milk”.
Rule of thumb: PUT sends the full object, PATCH sends only the changes. How a given API behaves is defined in its documentation, so always check.
Safe and Idempotent in Plain Words
Safe means the call does not change anything on the server. GET is safe.
Idempotent means doing it once or ten times leaves the server in the same state. GET, PUT and DELETE are idempotent: deleting the same item twice still leaves it deleted.
POST is not idempotent: sending it twice can create two to-dos. That is why a retry after a timeout needs care. PATCH depends on how it is designed.
Quick Reference
Method | Action | Example | Body | Typical status | Safe | Idempotent |
|---|---|---|---|---|---|---|
GET | Read | GET /todos/7 | No | 200 | Yes | Yes |
POST | Create | POST /todos | Yes | 201 | No | No |
PUT | Replace | PUT /todos/7 | Yes (full) | 200 or 204 | No | Yes |
PATCH | Update part | PATCH /todos/7 | Yes (changes) | 200 | No | Depends |
DELETE | Remove | DELETE /todos/7 | No | 204 | No | Yes |
Trying It in Python
This uses the requests library with a made-up URL, so it will not run against a real server. Swap in an API you can use.
import requests
BASE = "https://api.example.com/todos" # hypothetical URL
# GET: read the list
print(requests.get(BASE, timeout=10).json())
# POST: create a new to-do
r = requests.post(BASE, json={"title": "Buy milk", "done": False}, timeout=10)
todo = r.json()
print(r.status_code, todo) # expect 201
url = f"{BASE}/{todo['id']}"
# PATCH: change only one field
requests.patch(url, json={"done": True}, timeout=10)
# PUT: replace the whole to-do
requests.put(url, json={"title": "Buy oat milk", "done": True}, timeout=10)
# DELETE: remove it
r = requests.delete(url, timeout=10)
print(r.status_code) # expect 204To practise HTTP methods, status codes and headers properly, see the HTTP methods, status codes, headers and JSON chapter.
Common Mistakes
GET with side effects: a link like
GET /todos/7/deletecan be triggered by crawlers or prefetching. Use DELETE.Using POST for everything: it works, but you lose clear meaning, and caches and clients cannot reason about your API.
Wrong status codes: returning 200 for errors hides problems; use 201, 204, 400 and 404 as appropriate.
Treating PUT like PATCH and accidentally wiping fields.
Key Takeaway
GET reads, POST creates, PUT replaces, PATCH edits, DELETE removes. Remember which are safe and idempotent, and pick the method that says what you actually mean.
Ready to start? Learn how APIs work and build and call your own, with Git, Python and FastAPI. Begin with the free course Git, APIs and Backend for AI: Beginner.
Related articles
More in APIs and Backend
How to Keep API Keys Safe: .env Files and Secrets
Keep API keys out of your code: use .env files and environment variables, ignore them in Git, and know exactly what to do if a key leaks.
4 min readNov 14, 2026Frontend vs Backend: What's the Difference?
What the frontend and backend of an app are, how they differ, how they talk to each other and why AI calls and secret keys belong on the backend.
3 min readNov 12, 2026HTTP Status Codes Explained: 200, 404, 500 and More
What HTTP status codes mean, from 200 and 404 to 500, how the five groups work and how your code should react to each.
4 min readNov 9, 2026What Is JSON and Why Do APIs and AI Use It?
JSON is a simple text format for structured data. See what it looks like, its data types, how to read it in Python, and why APIs and AI apps depend on it.
3 min readNov 6, 2026What Are Git and GitHub? The Difference Explained
Git tracks your code's history on your computer; GitHub hosts it online for sharing and teamwork. Learn the difference, the key terms and your first commands.
4 min readNov 2, 2026What Is an API and How Does It Work?
An API explained with a restaurant analogy, then the real parts: endpoints, methods, JSON, status codes and API keys, with a small Python example.
4 min readOct 31, 2026
Comments
Sign in to join the discussion.

