This is my first project using Java and Spring Boot, where I explore building a simple RESTful API. The project demonstrates foundational concepts such as database integration, entity management, and REST endpoints.
- CRUD operations for managing data in a MySQL database.
- RESTful API endpoints built using Spring Web.
- Integration with JPA for database interaction.
- Hot reload support with Spring DevTools.
- Java Version: 17
- Spring Boot Version: 3.3.6
- Build Tool: Maven
- Database: MySQL(via XAMPP)
The project uses the following Spring Boot dependencies:
- MySQL Driver: For connecting the application to a MySQL database.
- Spring Data JPA: To simplify database operations and ORM integration.
- Spring Web: For creating RESTful APIs.
- Spring DevTools: To support live reload and faster development.
-
Clone the Repository
git clone https://github.com/PunMung-66/demorestapi.git cd demorestapi
-
Configure Database
Update theapplication.properties
file located insrc/main/resources
with your MySQL database credentials:spring.application.name=demorestapi spring.datasource.url=jdbc:mysql://localhost:3306/userdb spring.datasource.username=root spring.datasource.password= spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql: true
-
Run the Application
Run the application using the following Maven command:mvn spring-boot:run
-
Access the API
The application will start onhttp://localhost:8080
. Use tools like Postman or a browser to interact with the endpoints.
Method | Endpoint | Description |
---|---|---|
GET | /api/users |
Get all users |
GET | /api/users/{id} |
Get user by id |
POST | /api/users |
Save user(with Json body) |
PUT | /api/users |
Update an existing item |
DELETE | /api/users |
Delete an existing item |
Through this project, I learned:
- The basics of Java and Spring Boot.
- How to set up and configure a MySQL database in Spring Boot.
- The fundamentals of RESTful API design and implementation.
- Spring Boot Flow Architecture