Automated Action 06df0285b1 Implement Blogging Platform API with FastAPI and SQLite
- Set up project structure and dependencies
- Create database models for users, posts, comments, and tags
- Set up Alembic for database migrations
- Implement user authentication (register, login)
- Create CRUD endpoints for blog posts, comments, and tags
- Add health check endpoint
- Set up proper error handling
- Update README with project details and setup instructions
2025-06-02 21:58:50 +00:00

169 lines
4.1 KiB
Markdown

# Blogging Platform API
A RESTful API for a blogging platform built with FastAPI and SQLite.
## Features
- User authentication (register, login)
- Blog post management (CRUD operations)
- Comment system
- Tag/category support for blog posts
- Health check endpoint
- Proper error handling
- API documentation with Swagger and ReDoc
## Tech Stack
- **FastAPI**: Modern, fast web framework for building APIs with Python
- **SQLAlchemy**: SQL toolkit and Object-Relational Mapping (ORM)
- **SQLite**: Lightweight, serverless database
- **Alembic**: Database migration tool
- **Pydantic**: Data validation and settings management
- **JWT**: JSON Web Tokens for authentication
- **Uvicorn**: ASGI server
## Project Structure
```
.
├── alembic.ini
├── app
│ ├── api
│ │ ├── deps.py
│ │ ├── v1
│ │ │ ├── api.py
│ │ │ └── endpoints
│ │ │ ├── auth.py
│ │ │ ├── comments.py
│ │ │ ├── posts.py
│ │ │ ├── tags.py
│ │ │ └── users.py
│ ├── core
│ │ ├── config.py
│ │ └── security.py
│ ├── crud
│ │ ├── base.py
│ │ ├── crud_comment.py
│ │ ├── crud_post.py
│ │ ├── crud_tag.py
│ │ └── crud_user.py
│ ├── db
│ │ ├── base.py
│ │ ├── deps.py
│ │ └── session.py
│ ├── models
│ │ ├── comment.py
│ │ ├── post.py
│ │ ├── tag.py
│ │ └── user.py
│ ├── schemas
│ │ ├── comment.py
│ │ ├── post.py
│ │ ├── tag.py
│ │ ├── token.py
│ │ └── user.py
│ └── utils
│ └── errors.py
├── main.py
├── migrations
│ ├── env.py
│ ├── script.py.mako
│ └── versions
│ └── 0001_initial_migration.py
├── requirements.txt
└── storage
└── db
```
## Setup Instructions
### Prerequisites
- Python 3.8 or higher
- pip (Python package installer)
### Installation
1. Clone the repository:
```bash
git clone <repository-url>
cd blogging-platform-api
```
2. Create a virtual environment (optional but recommended):
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```
3. Install dependencies:
```bash
pip install -r requirements.txt
```
4. Set up environment variables (optional):
Create a `.env` file in the root directory with the following variables:
```
SECRET_KEY=your-secret-key
ACCESS_TOKEN_EXPIRE_MINUTES=10080 # 7 days
```
5. Run database migrations:
```bash
alembic upgrade head
```
### Running the Application
Start the FastAPI server:
```bash
uvicorn main:app --reload
```
The API will be available at `http://localhost:8000`
## API Documentation
- Swagger UI: `http://localhost:8000/docs`
- ReDoc: `http://localhost:8000/redoc`
- OpenAPI JSON: `http://localhost:8000/openapi.json`
## API Endpoints
### Authentication
- `POST /api/v1/auth/register`: Register a new user
- `POST /api/v1/auth/login`: Login and get access token
### Users
- `GET /api/v1/users/me`: Get current user
- `PUT /api/v1/users/me`: Update current user
### Blog Posts
- `GET /api/v1/posts`: List posts
- `POST /api/v1/posts`: Create a new post
- `GET /api/v1/posts/{id}`: Get a post by ID
- `PUT /api/v1/posts/{id}`: Update a post
- `DELETE /api/v1/posts/{id}`: Delete a post
### Comments
- `GET /api/v1/comments`: List comments
- `POST /api/v1/comments`: Create a new comment
- `GET /api/v1/comments/{id}`: Get a comment by ID
- `PUT /api/v1/comments/{id}`: Update a comment
- `DELETE /api/v1/comments/{id}`: Delete a comment
### Tags
- `GET /api/v1/tags`: List tags
- `POST /api/v1/tags`: Create a new tag
- `GET /api/v1/tags/{id}`: Get a tag by ID
- `PUT /api/v1/tags/{id}`: Update a tag
- `DELETE /api/v1/tags/{id}`: Delete a tag
### Health Check
- `GET /health`: Check if the API is up and running