A simple RESTful API built with Flask and Flask-RESTful for managing user data. This project uses SQLAlchemy for database operations and SQLite for data persistence.
- GET all users or a specific user by ID
- POST new users to the database
- PUT to update an entire user record
- PATCH to partially update a user record
- DELETE users from the database
- SQLite database for persistent storage
- Request validation and error handling
- Python 3.x
- Flask
- Flask-RESTful
- Flask-SQLAlchemy
See requirements.txt for a complete list of dependencies.
- Clone or download this project
- Install dependencies:
pip install -r requirements.txt
- Create the database:
python create_db.py
Start the Flask development server:
python api.pyThe server will run on http://localhost:5000 by default.
GET /api/users
GET /api/users/<user_id>
POST /api/users
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com"
}
PUT /api/users/<user_id>
Content-Type: application/json
{
"name": "Jane Doe",
"email": "jane@example.com"
}
PATCH /api/users/<user_id>
Content-Type: application/json
{
"name": "Jane Doe"
}
DELETE /api/users/<user_id>
GET /home
Returns a welcome message.
The application uses SQLite with the following User model:
- id (Integer): Primary key
- name (String): User's name (unique, required)
- email (String): User's email (unique, required)
.
├── api.py # Main Flask application
├── create_db.py # Database initialization script
├── requirements.txt # Python dependencies
└── README.md # This file