Skip to content

Latest commit

 

History

History
133 lines (114 loc) · 4.48 KB

README.md

File metadata and controls

133 lines (114 loc) · 4.48 KB

Blog Platform API

Description

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.

Table of Contents

Installation

  1. Clone the repository: git clone https://github.com/Maryousefi/BlogAPI-project.git
  2. Navigate to the project directory: cd blog-platform-api
  3. Create a virtual environment: python3 -m venv .venv
  4. Activate the virtual environment:
    • For macOS/Linux: source .venv/bin/activate
    • For Windows: .venv\Scripts\activate
  5. Install the required packages: pip install -r requirements.txt

Usage

  1. Run the application: uvicorn app.main:app --reload
  2. Open your browser and go to http://127.0.0.1:8000.

Frameworks and Tools

  • 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.

Configuration

  • 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.

Deployment

  1. Set up a server (e.g., AWS EC2, DigitalOcean Droplet).
  2. Install necessary dependencies (Python, PostgreSQL, etc.).
  3. Clone the repository and set up the virtual environment.
  4. Configure the database and environment variables.
  5. Run the application using a production-ready server (e.g., Gunicorn).

API Endpoints

Blog Post Management

  • 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 }
  • 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.
  • 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"] }
  • Delete a specific blog post:

    • Method: DELETE
    • URL: /posts/{post_id}/

Comment Management

  • 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 }
  • Retrieve all comments associated with a specific blog post:

    • Method: GET
    • URL: /posts/{post_id}/comments/

Testing

To run the tests, use the following command: bash pytest

CI/CD Pipeline

The project includes a CI/CD pipeline using GitHub Actions. The pipeline automatically runs tests and deploys the application to a staging environment.

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Commit your changes.
  4. Push to the branch.
  5. Submit a pull request.

License

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.