The Blog Platform API is a RESTful API that allows users to manage blog posts, including writing, editing, and commenting on them. The system stores each post in a database, including its text content, associated tags, and author details. The application provides a set of RESTful API endpoints for managing the blog posts and is deployable in a live environment.
- Installation
- Usage
- Frameworks and Tools
- Configuration
- Deployment
- API Endpoints
- Testing
- CI/CD Pipeline
- Contributing
- License
- Clone the repository: git clone https://github.com/Maryousefi/BlogAPI-project.git
- Navigate to the project directory: cd blog-platform-api
- Create a virtual environment: python3 -m venv .venv
- Activate the virtual environment:
- For macOS/Linux: source .venv/bin/activate
- For Windows: .venv\Scripts\activate
- Install the required packages: pip install -r requirements.txt
- Run the application: uvicorn app.main:app --reload
- Open your browser and go to
http://127.0.0.1:8000
.
- FastAPI: A modern, fast (high-performance) web framework for building APIs with Python 3.6+ based on standard Python type hints.
- SQLAlchemy: The Python SQL toolkit and Object Relational Mapper.
- Uvicorn: An ASGI web server implementation for Python.
- Passlib: A password hashing library for Python.
- Python 3.9: The programming language used for the project.
- Docker: Containerization platform for deploying the application.
- JWT: JSON Web Token for authentication and authorization.
- Database: PostgreSQL
- Secret Key: Generate a secret key for JWT tokens and store it securely.
- Environment Variables: Set environment variables for database URL, secret key, etc.
- Set up a server (e.g., AWS EC2, DigitalOcean Droplet).
- Install necessary dependencies (Python, PostgreSQL, etc.).
- Clone the repository and set up the virtual environment.
- Configure the database and environment variables.
- Run the application using a production-ready server (e.g., Gunicorn).
-
Create a new blog post:
- Method:
POST
- URL:
/posts/
- Request Body: json { "title": "New Blog Post", "content": "This is the content of the new blog post.", "tags": ["tag1", "tag2"], "author_id": 1 }
- Method:
-
Retrieve a paginated and filterable list of blog posts:
- Method:
GET
- URL:
/posts/
- Query Parameters:
date
: Filter by date.tags
: Filter by tags.keywords
: Filter by keywords.author
: Filter by author.
- Method:
-
Update a specific blog post:
- Method:
PUT
- URL:
/posts/{post_id}/
- Request Body: json { "title": "Updated Blog Post", "content": "This is the updated content of the blog post.", "tags": ["tag1", "tag3"] }
- Method:
-
Delete a specific blog post:
- Method:
DELETE
- URL:
/posts/{post_id}/
- Method:
-
Add a comment to a specific blog post:
- Method:
POST
- URL:
/posts/{post_id}/comments/
- Request Body: json { "content": "This is a comment on the blog post.", "author_id": 1 }
- Method:
-
Retrieve all comments associated with a specific blog post:
- Method:
GET
- URL:
/posts/{post_id}/comments/
- Method:
To run the tests, use the following command: bash pytest
The project includes a CI/CD pipeline using GitHub Actions. The pipeline automatically runs tests and deploys the application to a staging environment.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Commit your changes.
- Push to the branch.
- Submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
This README.md
file provides a comprehensive overview of the Blog Platform API, including installation instructions, usage details, technical requirements, and API endpoints. It also includes sections on testing, CI/CD pipeline, contributing, and licensing.