This project is a User Microservice built with Spring Boot 3.4 and PostgreSQL. It provides RESTful APIs for managing user entities (create, read, update, and delete). The application uses JPA for database interaction.
- User Microservice
- REST API with CRUD operations for managing users.
- PostgreSQL integration using Spring Data JPA.
- Credentials and sensitive data stored in an
.envfile, excluded from version control. - Configurable via
application.propertiesorapplication.yml. - Optional support for Docker containerization.
user-microservice/
├── .env # Environment file for credentials (ignored in VCS)
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── userservice/
│ │ │ └── user-service/
│ │ │ ├── controller/ # REST API Controllers
│ │ │ ├── service/ # Business logic
│ │ │ ├── repository/ # Data access layer (Repositories)
│ │ │ ├── entity/ # Database entities
│ │ │ ├── config/ # Application configuration
│ ├── resources/
│ │ ├── application.properties # Default configuration
│ │ └── application.yml # Alternative YAML configuration
├── .gitignore # Ensures .env and target are ignored
├── pom.xml # Project dependencies (Maven)
├── Dockerfile # Optional: For containerization
└── README.md # Project documentation for GitHub
Ensure you have the following installed on your system:
- Java 17 or later
- Maven (for dependency management)
- PostgreSQL (for database management)
First, clone the repository to your local machine:
git clone https://github.com/kumar-vibhanshu/user-service.git
cd user-service
Create an .env file at the root of the project and add your PostgreSQL credentials:
touch .envEnsure PostgreSQL is running and create a database:
CREATE DATABASE userdb;Run the following Maven command to start the Spring Boot application:
mvn spring-boot:runHere are the main endpoints for the User Microservice:
| Method | Endpoint | Description | Request Body |
|---|---|---|---|
| POST | /api/users |
Create a new user | { "name": "John", "email": "[email protected]", "password": "pass123" } |
| GET | /api/users |
Get all users | N/A |
| GET | /api/users/{id} |
Get a user by ID | N/A |
| DELETE | /api/users/{id} |
Delete a user by ID | N/A |
| PUT | /api/users/{id} |
Update a user by ID | N/A |
POST /api/users
Content-Type: application/json
{
"name": "John Doe",
"email": "[email protected]",
"password": "securepass"
}GET /api/usersGET /api/users/1DELETE /api/users/1You can optionally containerize the application using Docker.
- Ensure Docker is installed.
- Build the Docker image for the user microservice:
docker build -t user-service .Run the container with the following command:
docker run -d -p 8080:8080 --env-file .env user-serviceThis will start the microservice in a Docker container, mapping it to port 8080.