This project implements a REST API for a social media platform, offering endpoints for user management, post creation, and retrieval. Below are the services and features provided by the API:
The API includes robust exception handling mechanisms to gracefully handle unexpected errors and provide informative error messages to clients. This ensures a smooth user experience and helps in troubleshooting issues effectively.
Custom response messages are generated for different API endpoints and operations, ensuring consistency and clarity in the API responses. This allows clients to easily interpret the response and take appropriate actions based on the outcome of their requests.
Input validations are implemented using Bean Validation annotations (@Valid
) to enforce data integrity and prevent invalid requests. This ensures that the API receives valid data and avoids potential errors or inconsistencies in the database.
Swagger UI is integrated into the API to provide interactive documentation for the endpoints. This allows developers to explore and test the API easily without relying on external documentation. Swagger also helps in understanding the request and response formats required for each endpoint.
The API uses MySQL as the underlying relational database to store user information and posts. MySQL is a widely used database management system known for its reliability, scalability, and performance, making it suitable for storing social media data.
Spring Data JPA is utilized for database operations, providing convenient repository interfaces for CRUD (Create, Read, Update, Delete) operations on entities. Spring Data JPA simplifies database access by abstracting away the boilerplate code required for database interactions, resulting in cleaner and more maintainable code.
The API supports content negotiation, allowing clients to request responses in either JSON or XML format based on their preferences. Content negotiation enhances interoperability by accommodating different client requirements and ensuring flexibility in data exchange formats.
Internationalization (i18n) support is implemented to provide responses in multiple languages based on client preferences. This allows the API to cater to users from diverse linguistic backgrounds and enhance the user experience by delivering content in their preferred language.
Hypermedia as the Engine of Application State (HATEOAS) is implemented to provide navigation links along with API responses. HATEOAS enables clients to discover and navigate related resources dynamically, reducing coupling between clients and servers and improving the overall API usability.
HAL is implemented to represent API resources in a standardized hypermedia format, providing a consistent and uniform way to structure API responses. HAL enables clients to understand the relationships between resources and navigate the API seamlessly.
Spring Boot Actuator is integrated into the API to monitor and manage the application's health, metrics, and other useful information. Actuator endpoints expose valuable insights into the application's runtime behavior, facilitating operational tasks such as monitoring, troubleshooting, and performance optimization.
Basic authentication security is implemented to restrict access to certain endpoints and ensure data privacy. By requiring authentication, the API ensures that only authorized users can access sensitive resources, protecting user data from unauthorized access or tampering.
To run the Social Media REST API locally, follow these steps:
- Clone the repository to your local machine.
- Configure the MySQL database connection in the
application.yml
file. - Run the application using Maven or your preferred IDE.
- Access the API endpoints using a REST client like Postman or through the Swagger UI documentation.
- GET /users: Retrieve all users.
- GET /user/{userId}: Retrieve a specific user by ID.
- POST /user: Create a new user.
- PUT /user: Update an existing user.
- DELETE /user/{userId}: Delete a user by ID.
- GET /user/{userId}/posts: Retrieve all posts of a specific user.
- GET /users/posts: Retrieve all posts from all users.
- POST /user/{userId}/posts: Create a new post for a specific user.
- Spring Boot Starter Web
- Spring Boot Starter Security
- Spring Boot Starter HATEOAS
- Spring Boot Starter Validation
- Springdoc OpenAPI Starter Webmvc UI
- Jackson Dataformat XML
- Jakarta XML Bind API
- JAXB Runtime
- Spring Boot Starter Data JPA
- MySQL Connector J
- Spring Boot Starter Actuator
- Spring Boot DevTools
- Project Lombok
- [Paras Bagga]