A RESTful API for a blog platform built with Flask and PostgreSQL. This project features a comprehensive system for user management, blog post handling, comment management, notifications, and reporting. It includes secure authentication mechanisms with JWT tokens and a protected route example. The project also supports localization and internationalization.
- User Authentication: Register, log in, and log out users with JWT tokens.
- Blog Post Management: Create, read, update, and delete blog posts.
- Comment System: Add, view, update, and delete comments on blog posts.
- Notifications: Receive notifications for comments on blog posts.
- Reporting System: Report blog posts.
- Localization and Internationalization: Support for multiple languages.
- Protected Routes: Examples of routes protected by authentication tokens.
To get started with the Blog Platform API, follow these steps:
-
Clone the Repository
git clone https://github.com/yourusername/your-repository.git cd your-repository
-
Set Up Your Environment
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install Dependencies
pip install -r requirements.txt
-
Configure the Application
Set up your configuration values in
blog_platform/config.py
. Update the following variables:class Config: SECRET_KEY = 'your_secret_key' SQLALCHEMY_DATABASE_URI = 'postgresql://username:password@localhost:5432/your_database' REDIS_URL = 'redis://localhost:6379/0'
-
Run the Application
Start the application with:
python blog_platform/manage.py runserver
-
URL:
/blog/User/register
-
Method:
POST
-
Description: Register a new user.
-
Request Body:
{ "username": "exampleuser", "password": "examplepassword" }
-
Response:
{ "message": "User registered successfully." }
-
URL:
/blog/User/login
-
Method:
POST
-
Description: Log in an existing user and receive a JWT token.
-
Request Body:
{ "username": "exampleuser", "password": "examplepassword" }
-
Response:
{ "access_token": "<JWT_TOKEN>" }
-
URL:
/blog/User/logout
-
Method:
POST
-
Description: Log out the currently logged-in user by invalidating the JWT token.
-
Headers:
Authorization: Bearer <JWT_TOKEN>
-
Response:
{ "message": "User logged out successfully." }
-
URL:
/protected
-
Method:
GET
-
Description: Example of a protected route that requires a valid JWT token.
-
Headers:
Authorization: Bearer <JWT_TOKEN>
-
Response:
{ "message": "This is a protected route." }
To run the tests, use the following command:
pytest
To contribute to the Blog Platform project:
-
Create a Branch: Create a branch for your feature or bug fix.
git checkout -b feature/your-feature
-
Make Changes: Implement your changes and test them.
-
Submit a Pull Request: Submit a pull request with a description of your changes.
- Ensure that your code adheres to the project's coding standards.
- Provide clear descriptions of the changes and the reasons behind them.
- Include tests and documentation updates as needed.
This project is licensed under the MIT License. See the LICENSE file for details.