Hackforge Academy

Category: python

http methods get post put delete

Published on 30 Sep 2026

Explanation

GET is commonly used to retrieve resources from the server.

Code:

@app.route('/users', methods=['GET'])
def get_users():
    return {'users': ['Arun', 'Praveen']}

Explanation

POST is commonly used to create a new resource.

Code:

@app.route('/users', methods=['POST'])
def create_user():
    return {'message': 'User created'}, 201

Explanation

PUT is commonly used to update or replace an existing resource.

Code:

@app.route('/users/<int:id>', methods=['PUT'])
def update_user(id):
    return {'message': f'User {id} updated'}

Explanation

DELETE is commonly used to remove an existing resource.

Code:

@app.route('/users/<int:id>', methods=['DELETE'])
def delete_user(id):
    return {'message': f'User {id} deleted'}

Explanation

A typical REST API maps CRUD operations to HTTP methods.

Code:

GET    /users       → Read all
GET    /users/10    → Read one
POST   /users       → Create
PUT    /users/10    → Update
DELETE /users/10    → Delete

🚀 Learn Spring Boot with real-world projects

💡 Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
⚛️

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
☕

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community