This is a simple Flask + SQLAlchemy CRUD API for managing articles.
It provides endpoints to create, read, update, and delete articles from a database.
- Create new articles
- Retrieve all articles or a single article by ID
- Update existing articles
- Delete articles
- Environment-based database configuration
- Uses Flask blueprints for better project structure
.
├── app
│ ├── init.py
│ ├── database.py # Database
│ ├── routes.py # CRUD routes
├── run.py # Main entry point
├── .env.example # Example env
├── requirements.txt # Python dependencies
└── README.md # Documentation
git clone https://github.com/your-username/Personal-Blogging-Platform-Flask-API.git
cd Personal-Blogging-Platform-Flask-APIpython -m venv venv
pip install -r requirements.txt
Create a .env file in the root directory and add:
DATABASE_URL = "mysql+pymysql://root:password@localhost:3306/database_name"
You may replace the MySQL URL with PostgreSQL, SQLite, or any database supported by SQLAlchemy.
python run.pyThe application will start on:
http://127.0.0.1:5000
POST /create/article
Request Body (JSON):
{
"title": "My First Article",
"author": "John Doe",
"category": "Technology"
}Response:
{"Alert": "Success! Article has been created..."}GET /get/article
Response:
[
{
"title": "My First Article",
"author": "John Doe",
"category": "Technology"
}
]GET /get/article/<id>
Example: /get/article/1
Response:
{
"title": "My First Article",
"author": "John Doe",
"category": "Technology"
}PUT /update/article/<id>
Request Body (JSON):
{
"title": "Updated Title",
"author": "Jane Doe",
"category": "Science"
}Response:
{"Alert": "Success! Article has been updated..."}DELETE /delete/article/<id>
Example: /delete/article/1
Response:
{"Alert": "Updated Title by Jane Doe has been deleted..."}You can use [Postman](https://www.postman.com/downloads/) to test the API endpoints after running the application.- Method:
POST - URL:
http://127.0.0.1:5000/create/article - Body (JSON):
{
"title": "My First Article",
"author": "John Doe",
"category": "Technology"
}- Expected Response:
{"Alert": "Success! Article has been created..."}- Method:
GET - URL:
http://127.0.0.1:5000/get/article - Expected Response:
[
{
"title": "My First Article",
"author": "John Doe",
"category": "Technology"
}
]- Method:
GET - URL:
http://127.0.0.1:5000/get/article/1 - Expected Response:
{
"title": "My First Article",
"author": "John Doe",
"category": "Technology"
}- Method:
PUT - URL:
http://127.0.0.1:5000/update/article/1 - Body (JSON):
{
"title": "Updated Title",
"author": "Jane Doe",
"category": "Science"
}- Expected Response:
{"Alert": "Success! Article has been updated..."}- Method:
DELETE - URL:
http://127.0.0.1:5000/delete/article/1 - Expected Response:
{"Alert": "Updated Title by Jane Doe has been deleted..."}For quick testing, you can create a Postman Collection with all these endpoints so you can run them in sequence and see the responses.
- Python 3.8 or higher
- Flask
- SQLAlchemy
- python-dotenv
Install all dependencies:
pip install -r requirements.txt- The API runs in debug mode during development.
- For production, disable debug mode and run the application with a WSGI server such as Gunicorn.
- Compatible with any database supported by SQLAlchemy.