This is a FastAPI-based RESTful API for managing a blog system. It allows users to create, read, update, and delete blog posts, comment on posts, and like/dislike them. The data is stored in a MongoDB database.
- Create, read, update, and delete blog posts
- Add comments to blog posts
- Like or dislike blog posts
- Retrieve all blog posts
- FastAPI: Python web framework for building APIs quickly
- MongoDB: NoSQL database for data storage
- Pydantic: Data validation and serialization library
- Docker: Containerization for easy deployment
- Git/GitHub: Version control and collaboration
-
Clone the repository:
git clone https://github.com/sumeetbidhan/blogDB
-
Install dependencies:
pip install -r requirements.txt
-
Set up MongoDB:
- Install MongoDB locally or use a cloud-based service.
- Update the MongoDB connection string in
config/config.py.
-
Run the FastAPI server:
uvicorn main:app --reload
POST /blog: Create a new blog postPOST /comment/{post_id}: Add a comment to a blog postPOST /blog/like: Like or dislike a blog postGET /blog/{post_id}: Get a blog post by IDGET /blog/: Get all blog postsPATCH /blog/{_id}: Update a blog post by IDDELETE /blog/{_id}: Delete a blog post by ID
For detailed API documentation, visit http://localhost:8000/docs.
BlogModel: Represents a blog post with title, subtitle, content, author, and tags.CommentModel: Represents a comment with text and author.PostLikeModel: Represents a like or dislike action on a blog post.UpdateBlogModel: Represents the data model for updating a blog post.
DecodeBlog: Serialize blog data for responseDecodeBlogs: Serialize list of blogs for responseDecodeComment: Serialize comment data for responseDecodePostLike: Serialize like/dislike data for response
Contributions are welcome! Please fork the repository and submit a pull request.
- Fork the repository (
https://github.com/sumeetbidhan/blogDB/fork) - Create your feature branch (
git checkout -b feature/YourFeature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/YourFeature) - Create a new Pull Request
Feel free to modify and expand upon this template as needed to suit your project's specific details and requirements.
