The objective of this task is to create a RESTful API using Python's Flask framework that performs CRUD (Create, Read, Update, Delete) operations on user data. The API uses in-memory storage (a simple list) for managing users and supports HTTP methods: POST, GET, PUT, and DELETE.
- Language: Python
- Framework: Flask
- API Testing Tool: Postman
- IDE: VS Code
- Platform: Localhost (127.0.0.1:5000)
task-4-rest-api/ βββ app.py # Flask application βββ README.md βββ screenshots/ # Postman API testing screenshots βββ post-create-user.png βββ get-all-users.png βββ put-update-user.png βββ delete-user.png
- Add new users using POST /users
- Get a list of all users using GET /users
- Update a specific user by ID using PUT /users/
- Delete a user by ID using DELETE /users/
- JSON responses with meaningful status codes
- Handles both lowercase and capitalized JSON keys ("name" or "Name")
- Open terminal and install Flask:
pip install flask
- Run the Flask app:
python app.py
- Open Postman and test the API using:
Importing Modules:
We start by importing Flask and its required classes: Flask, request, and jsonify to create and handle web routes and responses.
Initializing App:
We create a Flask app instance using app = Flask(name).
In-Memory Database:
We define a Python list users = [] which stores user dictionaries containing id, name, and email.
- This route accepts JSON data via POST.
- It checks for either lowercase or capitalized keys (name or Name, email or Email).
- If either field is missing, it returns a 400 Bad Request.
- Otherwise, it creates a user, assigns an incremental ID, and appends it to the list.
- Returns 201 Created with user data.
- Returns the entire list of users.
- Responds with 200 OK.
- Accepts a user ID as a path parameter.
- Searches for the user with that ID.
- If found, returns the user data.
- If not found, returns 404 Not Found.
- Accepts user ID and JSON payload.
- Checks if the user exists.
- Updates name or email if present in the payload (case-insensitive).
- Returns updated user with 200 OK.
- Accepts user ID as a parameter.
- Removes the user from the list if they exist.
- Responds with confirmation message and 200 OK.
| Method | Endpoint | Description |
|---|---|---|
| POST | /users | Create a new user |
| GET | /users | Get all users |
| GET | /users/ | Get a user by ID |
| PUT | /users/ | Update user by ID |
| DELETE | /users/ | Delete user by ID |
All API requests were successfully tested in Postman.
| Method | Screenshot |
|---|---|
| β POST - Create User | ![]() |
| β GET - All Users | ![]() |
| β PUT - Update User | ![]() |
| β DELETE - Remove User | ![]() |
Each screenshot clearly displays:
- Correct request URL and method
- Proper headers and JSON body
- Successful status codes (200 OK, 201 Created)
- Valid JSON responses
- π‘ Fully working REST API using Flask
- π Supports all HTTP methods with complete CRUD functionality
- π¬ User-friendly error messages and validations
- π§ Accepts both name/Name and email/Email inputs for flexibility
- πΈ Well-documented Postman results with proof screenshots
- π§Ύ Professionally written README.md with full explanations
- π» Clean, maintainable, and scalable Python code
Name: Rohith K N
Internship: Python Development (1 Month)
Task Number: Task 4 - REST API using Flask
Date: June 2025
Goal: Top 10 out of 200 interns β¨



