A full-stack chess blog application with a Flask RESTful API backend and an interactive JavaScript frontend. Features include post management, pagination, sorting, and Swagger documentation.
- RESTful API endpoints for CRUD operations on blog posts
- API key authentication for secure access
- Rate limiting to prevent abuse
- Swagger UI documentation
- Pagination and sorting capabilities
- Advanced search functionality
- CORS support
- JSON-based data persistence
- Input validation using Marshmallow schemas
- Dynamic post loading with pagination
- Interactive post management (Create, Read, Update, Delete)
- Sortable posts by various fields
- Clean and responsive post display
- Form validation for post creation/editing
- Real-time updates after modifications
- Configurable API base URL
Backend:
- Python
- Flask
- Flask-CORS
- Flask-Limiter
- Flask-Swagger-UI
- Marshmallow
Frontend:
- HTML5
- JavaScript (Vanilla)
- CSS3
GET /api/v1/posts
- Retrieve paginated list of postsGET /api/v1/posts/<id>
- Get specific post by IDPOST /api/v1/posts
- Create new postPUT /api/v1/posts/<id>
- Update existing postDELETE /api/v1/posts/<id>
- Delete postGET /api/v1/posts/search
- Search posts
GET /api/docs
- Swagger UI documentationGET /swagger.json
- Swagger specification
- Python 3.x
- pip
- Web browser with JavaScript enabled
- Clone the repository:
git clone https://github.com/kaiser-data/Masterblog-API.git
cd Masterblog-API
- Install backend dependencies:
pip install -r requirements.txt
- Configure environment variables:
cp .env.example .env
# Edit .env with your settings
- Run the application:
python app.py
- Open
frontend/index.html
in your web browser
The API will be available at http://localhost:5001
API requests require an API key to be included either:
- In the request header:
X-API-Key: your-api-key
- As a query parameter:
?api_key=your-api-key
// Create/Update a post
function addOrUpdatePost() {
// Validates and submits post data
// Supports both creation and updates
}
// Delete a post
function deletePost(postId) {
// Removes post and refreshes display
}
// Load posts with pagination
function loadPosts(page) {
// Fetches posts for specified page
// Updates pagination controls
}
// Toggle sort direction
function toggleSort(field) {
// Sorts posts by specified field
// Toggles between ascending and descending
}
curl -X POST http://localhost:5001/api/v1/posts \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"title": "Opening Strategies",
"content": "The Sicilian Defense is a popular opening...",
"author": "Magnus Carlsen",
"date": "2025-02-18"
}'
curl "http://localhost:5001/api/v1/posts?page=1&per_page=5&sort=date&direction=desc" \
-H "X-API-Key: your-api-key"
curl "http://localhost:5001/api/v1/posts/search?query=sicilian&author=magnus" \
-H "X-API-Key: your-api-key"
The application can be configured through environment variables:
DEBUG
: Enable debug mode (default: False)API_KEY
: Authentication key for API accessRATE_LIMITS
: Rate limiting rules (default: "10 per minute")STORAGE_FILE
: Path to JSON storage file
Configure the API base URL in your HTML:
<input type="hidden" id="api-base-url" value="http://localhost:5001/api/v1">
- Default rate limit: 10 requests per minute per IP address
- Applies to all API endpoints
- Returns 429 Too Many Requests when limit is exceeded
Search posts using multiple criteria:
- General query across all fields
- Specific field search (title, content, author, date)
- Case-insensitive matching
- Partial word matching
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.