A simple yet robust RESTful API backend for a blog application built with Spring Boot. This project provides essential blogging functionality including user authentication, blog post management, and social features like comments and likes.
- User Authentication: Secure user registration and login
- Blog Management: Create, read, update, and delete blog posts
- Comments System: Add and manage comments on blog posts.
- Likes System: Like/unlike functionality for blog posts
- RESTful API: Clean and well-structured API endpoints
- Data Validation: Input validation and error handling
- Security: JWT-based authentication and authorization
- Framework: Spring Boot 3.x
- Database: MongoDB
- Security: Spring Security with JWT
- ODM: Spring Data MongoDB
- Build Tool: Maven
- Java Version: 17+
- Java 17 or higher
- Maven 3.6+
- MongoDB database
- IDE (IntelliJ IDEA, Eclipse, VS Code)
-
Clone the repository
git clone https://github.com/Lavish-code/BLOG_APP-BASIC-BACKEND-SPRINGBOO.git cd BLOG_APP-BASIC-BACKEND-SPRINGBOO -
Configure Database
- Update
application.propertieswith your MongoDB connection:
spring.data.mongodb.uri=mongodb://localhost:27017/blog_app # OR if using MongoDB Atlas spring.data.mongodb.uri=mongodb+srv://username:password@cluster.mongodb.net/blog_app
- Update
-
Install Dependencies
mvn clean install
-
Run the Application
mvn spring-boot:run
The application will start on http://localhost:8080
POST /api/auth/register- Register a new userPOST /api/auth/login- User login
GET /api/posts- Get all blog postsGET /api/posts/{id}- Get a specific blog postPOST /api/posts- Create a new blog postPUT /api/posts/{id}- Update a blog postDELETE /api/posts/{id}- Delete a blog post
GET /api/posts/{postId}/comments- Get comments for a postPOST /api/posts/{postId}/comments- Add a comment to a postDELETE /api/comments/{id}- Delete a comment
POST /api/posts/{postId}/like- Like/unlike a postGET /api/posts/{postId}/likes- Get likes count for a post
src/
├── main/
│ ├── java/
│ │ └── com/
│ │ └── blogapp/
│ │ ├── controller/ # REST Controllers
│ │ ├── service/ # Business Logic
│ │ ├── repository/ # Data Access Layer (MongoDB)
│ │ ├── model/ # MongoDB Documents
│ │ ├── dto/ # Data Transfer Objects
│ │ ├── config/ # Configuration Classes
│ │ └── security/ # Security Configuration
│ └── resources/
│ ├── application.properties
│ └── static/
└── test/
└── java/ # Unit Tests
- JWT token-based authentication
- Password encryption using BCrypt
- Role-based authorization
- CORS configuration
- Input validation and sanitization
POST /api/posts
{
"title": "My First Blog Post",
"content": "This is the content of my blog post...",
"author": "John Doe"
}{
"id": 1,
"title": "My First Blog Post",
"content": "This is the content of my blog post...",
"author": "John Doe",
"createdAt": "2024-01-15T10:30:00",
"likesCount": 0,
"commentsCount": 0
}Run the test suite:
mvn testKey configuration properties in application.properties:
# MongoDB Configuration
spring.data.mongodb.uri=mongodb://localhost:27017/blog_app
# OR for MongoDB Atlas
spring.data.mongodb.uri=mongodb+srv://username:password@cluster.mongodb.net/blog_app
# Application Configuration
server.port=8080
logging.level.org.springframework.data.mongodb=DEBUG
# JWT Configuration
jwt.secret=mySecretKey
jwt.expiration=86400000The application can be deployed on:
- Local server
- Cloud platforms (AWS, Azure, GCP)
- Docker containers
- Heroku
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Lavish - GitHub Profile
Project Link: https://github.com/Lavish-code/BLOG_APP-BASIC-BACKEND-SPRINGBOO
This project is open source and available under the MIT License.
⭐ If you found this project helpful, please give it a star on GitHub!