Hackforge Academy

Category: python

crud rest api with flask

Published on 30 Sep 2026

Explanation

A CRUD REST API supports Create, Read, Update, and Delete operations for a resource.

Code:

Create β†’ POST
Read   β†’ GET
Update β†’ PUT
Delete β†’ DELETE

Explanation

Create a user by accepting a JSON request body through a POST endpoint.

Code:

@app.post('/users')
def create_user():
    data = request.get_json()
    return {'message': 'User created', 'data': data}, 201

Explanation

Retrieve all users using a GET endpoint.

Code:

@app.get('/users')
def get_users():
    return {
        'users': []
    }

Explanation

Update a specific user using a PUT endpoint with a path parameter.

Code:

@app.put('/users/<int:id>')
def update_user(id):
    data = request.get_json()
    return {
        'id': id,
        'updated': data
    }

Explanation

Delete a specific user using a DELETE endpoint.

Code:

@app.delete('/users/<int:id>')
def delete_user(id):
    return {'message': f'User {id} deleted'}

πŸš€ 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