๐Ÿ“ API

HTTP Methods: GET, POST, PATCH, PUT, DELETE

P
Author
PyLand Team
๐Ÿ“…
Published
08.05.2026
โฑ๏ธ
Reading time
2 min
๐Ÿ‘๏ธ
Views
359
๐ŸŒฑ
Level
Beginner

In previous lessons we always used GET requests โ€” asking the server for data. But HTTP supports other methods for creating, updating, and deleting data as well.

The Five Core Methods

GET โ€” Retrieve data

The most common method. Data is passed only in the URL; the request body is empty.

import requests

# Get a list of repositories
response = requests.get("https://api.github.com/user/repos", headers=headers)

When to use: reading, searching, filtering โ€” any data retrieval that doesn’t modify anything.


POST โ€” Create a resource

Creates a new object. Data is sent in the request body as JSON.

# Create a repository
response = requests.post(
    "https://api.github.com/user/repos",
    headers=headers,
    json={"name": "my-new-repo", "private": False}  # โ† request body
)
# Success response: 201 Created

When to use: creating a new user, repository, issue, or order.


PUT โ€” Replace a resource entirely

Replaces the entire object. You must send all fields, even the ones you’re not changing.

# Replace the entire user profile
response = requests.put(
    "https://api.example.com/users/42",
    json={"name": "Alex", "email": "alex@example.com", "city": "Melbourne"}
)

When to use: full replacement of an object.


PATCH โ€” Partial update

Updates only the fields you send; everything else stays the same.

# Close an issue (change only the state field)
response = requests.patch(
    "https://api.github.com/repos/user/repo/issues/5",
    headers=headers,
    json={"state": "closed"}  # โ† only the field being changed
)

When to use: partial updates (changing a status, a single field).


DELETE โ€” Remove a resource

Deletes an object. The request body is typically empty; a successful response is 204 No Content.

# Delete a repository
response = requests.delete(
    "https://api.github.com/repos/user/old-repo",
    headers=headers
)
# Success response: 204 No Content

When to use: deleting objects.

The Key Difference Between GET and the Rest

GET POST / PUT / PATCH / DELETE
Data In the URL (?key=val) In the request body (json={})
Cached Yes No
Idempotent Yes POST โ€” no; PUT/DELETE โ€” yes
In a browser Address bar Only via code / form

Idempotent means the result is the same no matter how many times you repeat the call. GET a list of repositories five times โ€” you get the same list. POST “create repo” five times โ€” you get five separate repositories (or duplicate errors).

params= vs json= in requests

# GET โ€” data in the URL via params=
requests.get(url, params={"q": "python", "per_page": 10})
# Resulting URL: url?q=python&per_page=10

# POST โ€” data in the body via json=
requests.post(url, json={"name": "my-repo", "private": True})
# URL has no query params; body: {"name": "my-repo", "private": true}

json= automatically:
- Serializes the dictionary to a JSON string
- Adds the Content-Type: application/json header

Status Codes by Method

Method Success code
GET 200 OK
POST 201 Created
PUT / PATCH 200 OK
DELETE 204 No Content

CRUD โ€” The Standard Pattern

REST APIs are built around CRUD (Create, Read, Update, Delete):

CRUD HTTP Method Example
Create POST Create an issue
Read GET Get a list of issues
Update PUT / PATCH Close an issue
Delete DELETE Delete an issue

Your reaction to the article

๐Ÿ’ฌ Comments (0)

๐Ÿ” Sign in to leave a comment
๐Ÿšช Login
๐Ÿ’ญ

No comments yet

Be the first to share your opinion about this article!

๐Ÿ”— Similar

Similar articles

Continue learning with these materials

๐Ÿ“

REST API Design Principles

Covered topics: Resources and URLs, HTTP methods, Nested resources, Response codes.

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 273
๐Ÿ“

API Keys: What They Are and How to Use Them

Most public APIs require an API key โ€” a unique string that identifies you as...

๐Ÿ“… 08.05.2026 ๐Ÿ‘๏ธ 374
๐Ÿ“

The requests Library: HTTP Requests from Python

requests is the most downloaded Python library in the world โ€” over 300 million downloads...

๐Ÿ“… 08.05.2026 ๐Ÿ‘๏ธ 341