This project is a Spring Boot application for managing student data. It connects to a local MySQL database and provides REST APIs to perform CRUD operations on student records.
- Spring Web
- Spring Data JPA
- MySQL Driver
The project follows a layered architecture where requests from the API client (simulated with Postman) are directed to the API Layer. The API Layer contains REST APIs responsible for handling incoming requests. These APIs then delegate the business logic to the Service Layer. The Service Layer contains the business logic for the REST APIs. Finally, the Service Layer interacts with the Data Access Layer to perform database operations.
Components
- API Layer: Contains REST APIs for handling client requests.
- Service Layer: Implements business logic for managing student data.
- Data Access Layer: Uses the StudentRepository interface to interact with the MySQL database.
- Clone the repository:
git clone https://github.com/srahuliitb/SpringbootRestProject.git
-
Configure MySQL:
- Install MySQL on your local machine if you haven't already.
- Create a new database named student.
-
Update application.properties:
- Open
src/main/resources/application.properties.
- Update the MySQL database connection properties according to your MySQL setup.
- Provide your MySQL database credentials.
- Open
-
Build and run the application:
./mvnw spring-boot:run
-
Create Student
- URL:
http://localhost:8080/api/v1/student
- Method:
POST
- Request Body:
{ "name": "John Doe", "email": "Doe.John@example.com", "dob": 1990-01-30 }
- Response:
- Success:
HTTP 201 Created
- Failure:
HTTP 400 Bad Request
- Success:
- URL:
-
Get All Students
- URL:
http://localhost:8080/api/v1/student
- Method:
GET
- Response:
- Success:
HTTP 200 OK with a list of student records
- Failure:
HTTP 404 Not Found if no students found
- Success:
- URL:
-
Update Student
- URL:
http://localhost:8080/api/v1/student/1?name=Foo%20Bar&email=Bar.Foo@example.com
- Method:
PUT
- Request Body: None
- Response:
- Success:
HTTP 200 OK with the updated student record
- Failure:
HTTP 404 Not Found if the student with the specified ID does not exist
- Success:
- URL:
-
Delete Student
- URL:
http://localhost:8080/api/v1/student/{id}
- Method:
DELETE
- Response:
- Success:
HTTP 204 No Content
- Failure:
HTTP 404 Not Found if the student with the specified ID does not exist
- Success:
- URL:
You can test the API endpoints using tools like Postman or any other REST client. The project is yet to be tested with unit tests and integration tests.
Contributions are welcome! If you find any issues or have suggestions for improvement, please feel free to open an issue or create a pull request.