Masterblog API is a full-stack blog platform with a Flask-powered RESTful backend and a simple web-based frontend. It demonstrates modern Python backend design patterns, token-based user authentication, and essential CRUD operations via an API consumed by a dynamic frontend.
masterblog+API/ ├── backend/ │ └── backend_app.py ├── frontend/ │ ├── static/ │ ├── templates/ │ └── frontend_app.py ├── .gitignore ├── LICENSE └── README.md
- REST API for managing blog posts (Create, Read, Delete)
- User authentication with JWT tokens
- Search posts by keyword
- Sorting and pagination of posts
- Rate limiting and CORS support
- Simple, clean frontend to interact with the API
- Python 3.12+
- virtualenv
-
Clone the repository:
git clone git@github.com:rtaran/masterblog-API.git cd masterblog-API -
Create & activate a virtual environment:
python -m venv venv source venv/bin/activate # For Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Start the backend API:
python backend/backend_app.py
- Default: http://localhost:5002
-
Start the frontend application:
python frontend/frontend_app.py
- Default: http://localhost:5001
-
Authentication
POST /api/login— obtain JWT token
-
Posts
GET /api/posts— list all posts, supports sorting & paginationPOST /api/posts— create new post (JWT required)DELETE /api/posts/<id>— remove a post by ID (JWT required)GET /api/posts/search— search for posts by keyword
API query parameters:
sort(title, content, author, date),direction(asc, desc),page(int),limit(int),query(str, for search endpoint)
To perform operations that require authentication (creating or deleting posts), you need to obtain a JWT token:
-
Make a POST request to
/api/loginwith the following credentials:{ "username": "admin", "password": "password" } -
Example using curl:
curl -X POST http://localhost:5002/api/login \ -H "Content-Type: application/json" \ -d '{"username": "admin", "password": "password"}'
-
The response will contain your access token:
{ "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." }
Include the token in the Authorization header for protected endpoints:
-
Example of creating a new post with authentication:
curl -X POST http://localhost:5002/api/posts \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \ -d '{"title": "New Post", "content": "Post content", "author": "Your Name"}'
-
Example of deleting a post with authentication:
curl -X DELETE http://localhost:5002/api/posts/1 \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Replace YOUR_ACCESS_TOKEN with the actual token you received from the login endpoint.
Visit http://localhost:5001 after starting both servers to use the web UI.
Note: The current frontend implementation does not include authentication functionality. To add or delete posts, you'll need to use API tools like curl or Postman with the JWT token as described in the Authentication section above. The web UI can still be used to view and search posts.
To run all tests, ensure the virtual environment is activated, then: bash pytest
Distributed under the MIT License. See LICENSE for details.