The Social Media - API project provides APIs for user management (CRUD operations) with Spring Security, as well as APIs for managing posts (CRUD operations). The project is built using the Spring / Spring Boot framework, with a MySQL database, and Hibernate for ORM.
- User APIs:
- CRUD operations for user management.
- Integration with Spring Security for authentication and authorization.
- Post APIs:
- CRUD operations for managing posts.
- Spring / Spring Boot framework
- Spring Security
- Swagger Documentation
- Spring HATEOAS
- MySQL database
- Hibernate for ORM
To install and run this project locally, follow these steps:
-
Clone the repository:
git clone https://github.com/yourusername/social-media-api.git
-
Navigate to the project directory:
cd social-media-api
-
Configure the MySQL database:
- Option 1: Direct Configuration:
- Ensure MySQL is installed and running on your machine.
- Create a new database named
social_media_db
. - Update the database configurations in
application.properties
:spring.datasource.url=jdbc:mysql://localhost:3306/social_media_db spring.datasource.username=your_username spring.datasource.password=your_password
- Option 2: Using Docker (if Docker is installed):
- Run the MySQL Docker container:
docker run -d -p 3306:3306 --name social-media-db -e MYSQL_ROOT_PASSWORD=your_password -e MYSQL_DATABASE=social_media_db mysql:latest
- Update the database configurations in
application.properties
:spring.datasource.url=jdbc:mysql://localhost:3306/social_media_db spring.datasource.username=root spring.datasource.password=your_password
- Run the MySQL Docker container:
- Option 1: Direct Configuration:
-
Build the project using Maven:
mvn clean install
-
Run the application:
java -jar target/social-media-api.jar
-
The API will be accessible at
http://localhost:8080
.
- Endpoint:
POST /api/users
- Description: Create a new user.
- Request Body:
{ "username": "example_user", "email": "example@example.com", "password": "password123" }
- Response: Returns the newly created user object.
- Endpoint:
GET /api/users/{userId}
- Description: Get details of a specific user.
- Parameters:
{userId}
: ID of the user to retrieve.
- Response: Returns the user object.
- Endpoint:
PUT /api/users/{userId}
- Description: Update details of a specific user.
- Parameters:
{userId}
: ID of the user to update.
- Request Body:
{ "username": "updated_user", "email": "updated@example.com" }
- Response: Returns the updated user object.
- Endpoint:
DELETE /api/users/{userId}
- Description: Delete a specific user.
- Parameters:
{userId}
: ID of the user to delete.
- Response: Returns a success message.
- Endpoint:
POST /api/posts
- Description: Create a new post.
- Request Body:
{ "userId": "userId", "content": "This is a sample post." }
- Response: Returns the newly created post object.
- Endpoint:
GET /api/posts/{postId}
- Description: Get details of a specific post.
- Parameters:
{postId}
: ID of the post to retrieve.
- Response: Returns the post object.
- Endpoint:
PUT /api/posts/{postId}
- Description: Update details of a specific post.
- Parameters:
{postId}
: ID of the post to update.
- Request Body:
{ "content": "Updated content." }
- Response: Returns the updated post object.
- Endpoint:
DELETE /api/posts/{postId}
- Description: Delete a specific post.
- Parameters:
{postId}
: ID of the post to delete.
- Response: Returns a success message.
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
This project is licensed under the MIT License - see the LICENSE.md file for details.
- Spring for providing the powerful Spring framework.
- Hibernate for ORM capabilities.
- Swagger for API documentation.
- Spring HATEOAS for hypermedia-driven REST APIs.
- in28minutes for helping to learn the concepts of Spring Boot and backend development.