Employee API
Employee API
This project is a Spring Boot application providing a RESTful API for managing employee data. The application supports operations such as creating, updating, deleting, and fetching employee details.
Table of Contents
- Features
- Technologies Used
- Prerequisites
- Setup
- Running the Application
- API Endpoints
- Running in Docker
- Deploying to Azure
- Access Live API
- Contributing
- License
Features
- Create, update, delete, and retrieve employees.
- Delete all employees.
- Reload employee data from a predefined CSV dataset.
- API documentation with Swagger.
Technologies Used
- Java
- Spring Boot
- Spring Data JPA
- H2 Database
- Swagger/OpenAPI
- Docker
Prerequisites
- Java 17 or higher
- Maven 3.6 or higher
- Docker (optional, for containerization)
- An Azure account (optional, for deployment)
Setup
-
Clone the repository:
git clone https://github.com/raazankeet/employee-api.git cd employee-api
-
Build the application:
mvn clean package -DskipTests
Running the Application
-
Start the application:
mvn spring-boot:run
-
The API will be accessible at
http://localhost:8080
.
API Endpoints
Get All Employees
- URL:
/api/employees
- Method:
GET
- Description: Retrieve a list of all employees.
Get Employee by ID
- URL:
/api/employees/{id}
- Method:
GET
- Description: Retrieve an employee by their unique ID.
Create Employee
- URL:
/api/employees
- Method:
POST
- Description: Add a new employee to the system.
- Body: JSON representation of the employee.
Update Employee
- URL:
/api/employees/{id}
- Method:
PUT
- Description: Update the details of an existing employee.
- Body: JSON representation of the updated employee.
Delete Employee
- URL:
/api/employees/{id}
- Method:
DELETE
- Description: Remove an employee from the system.
Delete All Employees
- URL:
/api/employees
- Method:
DELETE
- Description: Remove all employees from the system.
Reload Employee Data
- URL:
/api/employees/reload
- Method:
POST
- Description: Reload the employee data from a predefined CSV dataset.
Running in Docker
-
Build the Docker image:
docker build -t employee-api .
-
Run the Docker container:
docker run -p 8080:8080 employee-api
Deploying to Azure
-
Ensure you have the Azure CLI installed and are logged in.
-
Create a resource group:
az group create --name employee-api-rg --location eastus
-
Create an App Service plan:
az appservice plan create --name employee-api-plan --resource-group employee-api-rg --sku B1 --is-linux
-
Create a web app:
az webapp create --resource-group employee-api-rg --plan employee-api-plan --name myemployeesapi --deployment-container-image-name raazankeet/employee-api:latest
-
Configure continuous deployment from your Docker repository:
az webapp config container set --name myemployeesapi --resource-group employee-api-rg --docker-custom-image-name raazankeet/employee-api:latest --docker-registry-server-url https://index.docker.io
Access Live API
You can access the live API at: https://myemployeesapi.azurewebsites.net/
Contributing
Contributions are welcome! Please submit a pull request or open an issue to discuss any changes.
License
This project is licensed under the custom License. See the LICENSE file for details.