This is a REST API designed for a social media application. It provides endpoints for managing users, posts, and comments. Built with the latest technologies, it leverages the power of Spring Boot and MongoDB to deliver a robust and scalable solution for social media features.
- Java 21
- Spring Framework
- Spring Boot 3.4.1
- Spring Data MongoDB
- MongoDB 8.0.4
- Maven
- User Module: Handles user management.
- Post Module: Manages posts created by users.
- Comment Module: Manages comments on posts.
- To run the API, follow the steps below:
- Update the database configuration inside the application.yaml file.
- Set your local database URI and port number.
server:
port: 8081
spring:
data:
mongodb:
uri: mongodb://localhost:27017/app_db
https://localhost:8081/api
GET /users:
Returns a list of users.GET /users/{id}
: Returns a user by ID.GET /users/{id}/posts
: Returns the posts of a user by their ID.POST /users
: Creates a new user.DELETE /users/{id}
: Deletes a user by ID.PUT /users/{id}
: Updates a user by ID.
GET /posts
: Returns a list of posts.GET /posts/{id}
: Returns a post by ID.GET /posts/searchtext?text
: Returns posts that contain the searched text in their title, body, or comments.GET /posts/{id}/comments
: Returns comments for a post by its ID.POST /posts
: Creates a new post.DELETE /posts/{id}
: Deletes a post by ID.PUT /posts/{id}
: Updates a post by ID.
GET /comments
: Returns a list of comments.GET /comments/{id}
: Returns a comment by ID.POST /comments/{id}
: Creates a comment for a post by its ID.DELETE /comments/{id}
: Deletes a comment by ID.PUT /comments/{id}
: Updates a comment by ID.
GET localhost:8081/api/posts/678e921efae5ff2f043f0b88
- Response
{
"id": "678e921efae5ff2f043f0b88",
"date": "2024-01-15T08:30:00Z",
"title": "Exploring the Future of Technology",
"body": "Technology is evolving rapidly, with innovations that promise to transform our lives. In this post, we will explore some of these technologies and their impact.",
"author": {
"id": "678e921efae5ff2f043f0b85",
"name": "Maria Brown"
}
}