Post Management API
A simple FastAPI application for managing posts with SQLite backend, user authentication, and comprehensive logging.
Features
- User Management with JWT Authentication
- CRUD operations for posts (Create, Read, Update, Delete)
- Post ownership and authorization controls
- Paginated API responses
- SQLite database integration with SQLAlchemy
- Comprehensive logging system with file rotation
- Request timing and monitoring
- Input validation using Pydantic models
- Modern FastAPI practices with lifespan management
API Flow Diagram
flowchart TD
A[<font color=black>Client</font>]
B[<font color=black>FastAPI App</font>]
C[<font color=black>Router Layer</font>]
D[<font color=black>Database Layer</font>]
E[<font color=black>Logging System</font>]
F[<font color=black>SQLite DB</font>]
K[<font color=black>Auth Layer</font>]
A -->|HTTP Request| B
B -->|Authenticate| K
K -->|Validate| D
B -->|Route| C
C -->|Query| D
D -->|Store/Retrieve| F
B -->|Log Request| E
C -->|Log Operation| E
D -->|Log DB Event| E
subgraph Operations
G[<font color=black>Create Post</font>]
H[<font color=black>Read Post</font>]
I[<font color=black>Update Post</font>]
J[<font color=black>Delete Post</font>]
L[<font color=black>User Auth</font>]
end
C --> Operations
classDef client fill:#FFD700,stroke:#333,stroke-width:2px;
classDef api fill:#98FB98,stroke:#333,stroke-width:2px;
classDef data fill:#87CEEB,stroke:#333,stroke-width:2px;
classDef logs fill:#FFA07A,stroke:#333,stroke-width:2px;
classDef ops fill:#DDA0DD,stroke:#333,stroke-width:2px;
classDef auth fill:#FF69B4,stroke:#333,stroke-width:2px;
class A client;
class B,C api;
class D,F data;
class E logs;
class G,H,I,J,L ops;
class K auth;
Installation
- Ensure Python 3.8+ is installed
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
Project Structure
.
βββ logs/ # Application logs directory
β βββ app_YYYYMMDD.log # Daily rotating log files
βββ src/
β βββ database/
β β βββ __init__.py
β β βββ config.py # Database configuration and session
β β βββ models.py # SQLAlchemy database models
β βββ models/
β β βββ __init__.py
β β βββ post.py # Pydantic models for posts
β β βββ user.py # Pydantic models for users
β βββ router/
β β βββ __init__.py
β β βββ post_router.py # Post CRUD endpoints
β β βββ user_router.py # User management endpoints
β βββ utils/
β βββ __init__.py
β βββ auth.py # Authentication utilities
β βββ logger.py # Logging configuration
βββ main.py # FastAPI application entry point
βββ requirements.txt # Project dependencies
βββ README.md # Project documentation
API Endpoints
Authentication
POST /users/register- Register a new userPOST /users/login- Login and get access tokenGET /users/me- Get current user information
Posts
GET /posts- List all posts (paginated)- Query parameters:
skip: Number of posts to skip (default: 0)limit: Number of posts per page (default: 10, max: 100)
- Returns:
items: List of poststotal: Total number of postsskip: Current skip valuelimit: Current limit value
- Query parameters:
GET /posts/{id}- Get a specific postPOST /posts- Create a new post (requires authentication)PUT /posts/{id}- Update an existing post (requires authentication, owner only)DELETE /posts/{id}- Delete a post (requires authentication, owner only)
Running the Application
python main.py
The API will be available at http://127.0.0.1:8000
Authentication
The API uses JWT (JSON Web Tokens) for authentication:
- Register a new user with username and password
- Login to receive an access token
- Include the token in subsequent requests:
Authorization: Bearer <your_access_token>
Logging
Logs are stored in the logs directory with:
- Daily rotation
- 1MB file size limit
- 5 backup files retained
- Both file and console output
- Request timing information
- Operation tracking for all CRUD operations
- Authentication events logging
API Documentation
- Swagger UI:
http://127.0.0.1:8000/docs - ReDoc:
http://127.0.0.1:8000/redoc
Post Management API
by Kekniskd
198
Project Details
- Kekniskd/cursor-IDE-API
- Last Updated: 3/2/2025
Recomended MCP Servers
κ·Έμ λλ²κΉ
μ©
π§©
LaTeX to MathML Server
A Model Context Protocol (MCP) server that converts LaTeX mathematical expressions to MathML format.
π§©
Psychological Plus
ε£ΉεΏηζ΅θ―+ε°η¨εΊζΊη
Remote MCP Server on Cloudflare Workers
π§©
Game Asset Generator
An MCP server for creating 2D/3D game assets from text using Hugging Face AI models.
π§©
Ebay MCP Server
kintone
MCP server for kintone
Google Analytics Data API Server
A MCP server for Google Analytics Data API
Python Sandbox Server
Python sandboxes for llms
π§©
Speedy
π§©
mcp-scholar
Typesense MCP Server





