A Spring Boot REST API project for a social media application demonstrating core backend development concepts and best practices. Built as a learning reference covering RESTful design, JPA/Hibernate, exception handling, API versioning, Swagger documentation, and more.
| Layer | Technology |
|---|---|
| Framework | Spring Boot 2.4.5 |
| Language | Java 11 |
| Build Tool | Maven |
| Database | H2 (in-memory) |
| ORM | Spring Data JPA / Hibernate |
| API Docs | Springfox Swagger 3.0 |
| Monitoring | Spring Boot Actuator |
| REST Extras | HATEOAS, HAL Explorer |
| Validation | Spring Boot Validation |
myNewProject/
├── pom.xml
└── src/
└── main/
├── java/com/mynewproject/myNewProject/
│ ├── MyNewProjectApplication.java # App entry point + i18n config
│ ├── SwaggerConfig.java # Swagger/OpenAPI configuration
│ │
│ ├── user/ # Core social media feature
│ │ ├── User.java # JPA entity
│ │ ├── Post.java # JPA entity
│ │ ├── UserRepository.java # Spring Data JPA repository
│ │ ├── PostRepository.java # Spring Data JPA repository
│ │ ├── UserDaoService.java # In-memory DAO (demo purposes)
│ │ ├── UserNotFoundException.java # Custom 404 exception
│ │ ├── UserReources.java # REST controller (in-memory DAO)
│ │ └── UserJPAResources.java # REST controller (JPA/database)
│ │
│ ├── exception/ # Global exception handling
│ │ ├── CustomisedResponseEntityExceptionHandler.java
│ │ └── ExceptionResponse.java
│ │
│ ├── helloWorld/ # Basic Spring REST examples + i18n
│ │ ├── HelloWorldController.java
│ │ └── HelloBoy.java
│ │
│ └── versioning/ # API versioning strategies demo
│ ├── PersonVersionController.java
│ ├── PersonV1.java
│ ├── Personv2.java
│ └── Name.java
│
└── resources/
├── application.properties
├── data.sql # H2 seed data
├── messages.properties # English (default)
├── messages_fr.properties # French
└── messages_hi.properties # Hindi
| Method | Endpoint | Description |
|---|---|---|
| GET | /users |
Get all users |
| GET | /users/{id} |
Get user by ID (with HATEOAS links) |
| POST | /users |
Create a new user |
| DELETE | /users/{id} |
Delete a user |
| Method | Endpoint | Description |
|---|---|---|
| GET | /JPA/users |
Get all users |
| GET | /JPA/users/{id} |
Get user by ID |
| POST | /JPA/users |
Create a new user |
| DELETE | /JPA/users/{id} |
Delete a user |
| GET | /JPA/users/{id}/posts |
Get all posts by a user |
| POST | /JPA/users/{id}/posts |
Create a post for a user |
| Method | Endpoint | Description |
|---|---|---|
| GET | /hello-world |
Basic hello world |
| GET | /hello-boy |
Returns JSON object |
| GET | /hello-boy/pathvariable/{name} |
Path variable demo |
| GET | /hello-boy-internationalised |
i18n demo (set Accept-Language header) |
| Method | Endpoint | Description |
|---|---|---|
| GET | /v1/person |
URI versioning — v1 |
| GET | /v2/person |
URI versioning — v2 |
| GET | /person/param?version=1 |
Request param versioning |
| GET | /person/param?version=2 |
Request param versioning |
| GET | /person/header |
Header versioning (X-API-VERSION: 1 or 2) |
| GET | /person/produces |
Content negotiation versioning (Accept header) |
Prerequisites: Java 11+, Maven 3.6+
cd myNewProject
./mvnw spring-boot:runThe app starts on http://localhost:8080
| URL | Description |
|---|---|
| http://localhost:8080/swagger-ui.html | Swagger API documentation UI |
| http://localhost:8080/v2/api-docs | Swagger JSON spec |
| http://localhost:8080/actuator | All actuator endpoints |
| http://localhost:8080/h2-console | H2 database console |
| http://localhost:8080/browser | HAL Explorer |
H2 Console settings: JDBC URL
jdbc:h2:mem:testdb, no password needed.
Uses H2 in-memory database seeded via data.sql on startup:
- 3 Users: Hardik, Hitesh, Mayank
- 3 Posts: 2 by Hardik, 1 by Mayank
Schema is auto-generated by Hibernate from JPA entities.
- RESTful API design — GET, POST, DELETE with proper HTTP status codes
- JPA / Hibernate — Entity mapping, repositories, relationships (One-to-Many)
- Exception handling — Global
@ControllerAdvicewith custom error responses - HATEOAS — Hypermedia links in API responses
- API Versioning — URI, request param, header, and content negotiation strategies
- Internationalization (i18n) —
Accept-Languageheader support (EN, FR, HI) - Validation — Bean validation (
@Size,@Past) with error responses - Swagger — Auto-generated interactive API documentation
- Actuator — Application health and metrics endpoints
Default credentials in application.properties (hardik / 12345678) are for local development only. Never commit real credentials to source control.