
REST API Methods
What is a REST API?
A REST API is a way for different applications to communicate with each other over the internet using HTTP.
For example, a frontend application can communicate with a FastAPI backend through REST APIs to:
- Get user information
- Create an account
- Update a profile
- Delete a post
REST APIs mainly use different HTTP methods to tell the server what action should be performed.
Main REST API Methods
The most commonly used HTTP methods are:
| Method | Purpose | Example |
|---|---|---|
| GET | Read data | Get all users |
| POST | Create data | Create a new user |
| PUT | Replace data | Replace a user profile |
| PATCH | Partially update data | Change only the user's email |
| DELETE | Remove data | Delete a user |
1. GET
GET is used to retrieve or read data from the server.
Example:
GET /users
The server might return:
[
{"id": 1, "name": "Charan"},
{"id": 2, "name": "Rahul"}
]
Important point
GET should normally not change data on the server.
2. POST
POST is used to create new data.
Example:
POST /users
Request body:
{
"name": "Charan",
"email": "[email protected]"
}
The server creates the new user and may return:
{
"id": 3,
"name": "Charan",
"email": "[email protected]"
}
Simple idea
POST = Create something new.
3. PUT
PUT is generally used to replace an existing resource completely.
Example:
PUT /users/3
Request:
{
"name": "Charan Kumar",
"email": "[email protected]"
}
The server replaces the existing user information with the supplied representation.
Simple idea
PUT = Replace the resource.
4. PATCH
PATCH is used when you want to partially update a resource.
For example, if you only want to change the email:
PATCH /users/3
Request:
{
"email": "[email protected]"
}
Other user information remains unchanged.
Simple idea
PATCH = Change only what is needed.
5. DELETE
DELETE is used to remove a resource.
Example:
DELETE /users/3
The server removes the user with ID 3.
Simple idea
DELETE = Remove something.
REST API Methods in FastAPI
FastAPI provides decorators for these HTTP methods:
from fastapi import FastAPI
app = FastAPI()
@app.get("/users")
def get_users():
return {"message": "Get users"}
@app.post("/users")
def create_user():
return {"message": "User created"}
@app.put("/users/{id}")
def update_user(id: int):
return {"message": "User replaced"}
@app.patch("/users/{id}")
def update_partially(id: int):
return {"message": "User partially updated"}
@app.delete("/users/{id}")
def delete_user(id: int):
return {"message": "User deleted"}
CRUD and REST Methods
REST methods are closely related to CRUD operations:
| CRUD | HTTP Method | Action |
|---|---|---|
| Create | POST | Create data |
| Read | GET | Read data |
| Update | PUT / PATCH | Update data |
| Delete | DELETE | Delete data |

GET → Give me data
POST → Create data
PUT → Replace data
PATCH → Change part of data
DELETE → Remove data
Join Techsnap Creators
Share your knowledge and earn ??
Want to showcase your tech expertise and get rewarded for your insights? Join the Techsnap creator network!
Write insightful blogs, stay ahead of industry trends, and grow your professional brand while helping others in the community.
Ready to make an impact?

Comments