Skip to content

kumar-vibhanshu/user-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

User Microservice

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.

Table of Contents


Features

  • REST API with CRUD operations for managing users.
  • PostgreSQL integration using Spring Data JPA.
  • Credentials and sensitive data stored in an .env file, excluded from version control.
  • Configurable via application.properties or application.yml.
  • Optional support for Docker containerization.

Project Structure

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

Prerequisites

Ensure you have the following installed on your system:

  • Java 17 or later
  • Maven (for dependency management)
  • PostgreSQL (for database management)

Setup

Clone the repository

First, clone the repository to your local machine:

git clone https://github.com/kumar-vibhanshu/user-service.git
cd user-service

Configure environment variables

Create an .env file at the root of the project and add your PostgreSQL credentials:

touch .env

Run PostgreSQL

Ensure PostgreSQL is running and create a database:

CREATE DATABASE userdb;

Run the application

Run the following Maven command to start the Spring Boot application:

mvn spring-boot:run

API Documentation

User API Endpoints

Here 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

Example POST Request (Create a User)

POST /api/users
Content-Type: application/json
{
  "name": "John Doe",
  "email": "[email protected]",
  "password": "securepass"
}

Example GET Request (Get All Users)

GET /api/users

Example GET Request (Get a User by ID)

GET /api/users/1

Example DELETE Request (Delete a User by ID)

DELETE /api/users/1

Docker Setup (Optional)

You can optionally containerize the application using Docker.

Build Docker Image

  1. Ensure Docker is installed.
  2. Build the Docker image for the user microservice:
docker build -t user-service .

Run the Docker Container

Run the container with the following command:

docker run -d -p 8080:8080 --env-file .env user-service

This will start the microservice in a Docker container, mapping it to port 8080.

About

User microservice with spring boot

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages