A comprehensive RESTful API for managing employee data with built-in pagination, sorting, and hypermedia support using HAL+JSON format.
- Full CRUD Operations - Create, Read, Update, and Delete employees
- Pagination Support - Efficient handling of large datasets
- Flexible Sorting - Multiple sort criteria with ascending/descending options
- HAL+JSON Compliance - Hypermedia-driven API with discoverable links
- Spring Boot Integration - Built with Spring Data REST for rapid development
- Profile Endpoints - API discoverability and metadata
- Java 11 or higher
- Maven 3.6+
- Spring Boot 2.5+
- Clone the repository
git clone <your-repository-url>
cd employee-management-api- Build the project
mvn clean install- Run the application
mvn spring-boot:runThe API will be available at http://localhost:8080
Interactive API documentation is available at:
- Swagger UI:
http://localhost:8080/swagger-ui.html - OpenAPI Spec:
http://localhost:8080/v3/api-docs
| Method | Endpoint | Description |
|---|---|---|
GET |
/magic-api/members |
List all employees (paginated) |
POST |
/magic-api/members |
Create a new employee |
GET |
/magic-api/members/{id} |
Get employee by ID |
PUT |
/magic-api/members/{id} |
Update employee (full replacement) |
PATCH |
/magic-api/members/{id} |
Partial update of employee |
DELETE |
/magic-api/members/{id} |
Delete employee |
| Method | Endpoint | Description |
|---|---|---|
GET |
/magic-api/profile |
Get API profile information |
GET |
/magic-api/profile/members |
Get members resource profile |
GET /magic-api/members?page=0&size=10&sort=lastName,asc HTTP/1.1
Host: localhost:8080
Accept: application/hal+jsonResponse:
{
"_embedded": {
"employees": [
{
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@example.com",
"_links": {
"self": {
"href": "http://localhost:8080/magic-api/members/1"
}
}
}
]
},
"_links": {
"self": {
"href": "http://localhost:8080/magic-api/members?page=0&size=10"
},
"next": {
"href": "http://localhost:8080/magic-api/members?page=1&size=10"
}
},
"page": {
"size": 10,
"totalElements": 25,
"totalPages": 3,
"number": 0
}
}POST /magic-api/members HTTP/1.1
Host: localhost:8080
Content-Type: application/json
{
"firstName": "Jane",
"lastName": "Smith",
"email": "jane.smith@example.com"
}PUT /magic-api/members/1 HTTP/1.1
Host: localhost:8080
Content-Type: application/json
{
"firstName": "John",
"lastName": "Doe",
"email": "john.doe.updated@example.com"
}| Field | Type | Required | Description |
|---|---|---|---|
firstName |
String | Yes | Employee's first name |
lastName |
String | Yes | Employee's last name |
email |
String | Yes | Employee's email address |
| Parameter | Type | Default | Description |
|---|---|---|---|
page |
Integer | 0 | Zero-based page index |
size |
Integer | 20 | Number of items per page |
sort |
String[] | - | Sort criteria: property,(asc|desc) |
The API supports multiple response formats:
application/hal+json(default) - HAL hypermedia formatapplication/x-spring-data-compact+json- Compact Spring Data formattext/uri-list- URI list format
The API returns standard HTTP status codes:
200 OK- Successful GET, PUT, PATCH201 Created- Successful POST204 No Content- Successful DELETE400 Bad Request- Invalid request data404 Not Found- Resource not found500 Internal Server Error- Server error
Error responses follow the standard format:
{
"timestamp": "2024-01-15T10:15:30.000Z",
"status": 400,
"error": "Bad Request",
"message": "Validation failed",
"path": "/magic-api/members"
}# Server Configuration
server.port=8080
# Database Configuration
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driver-class-name=org.h2.Driver
spring.jpa.hibernate.ddl-auto=update
# HAL Configuration
spring.data.rest.base-path=/magic-api
spring.data.rest.default-page-size=20
spring.data.rest.max-page-size=100Run the test suite:
mvn test- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Created and maintained by [Shivansh Pal]
- Spring Boot team for the excellent framework
- Spring Data REST for hypermedia support
- OpenAPI for API documentation standards
For questions or support, please open an issue in the repository.