Spring Boot Bootcamp – Workbooks and Challenges
)}

Workbook 9.1

The grade-submission API will serve as a mediator between a consumer and the resources in an SQL database.

Screen Shot 2022-07-21 at 6.49.32 PM.png

Workbook 9.1 will prepare the REST endpoints for the StudentController.

Screen Shot 2022-07-21 at 6.55.45 PM.png

Launch the Starter Project

Screen Shot 2022-07-21 at 6.58.16 PM.png

@RequestMapping

maps a web request at the class or method level.

This code maps any web request that starts with /student to the StudentController bean.

Screen Shot 2022-07-21 at 7.06.42 PM.png

GET Request

Create a method:

  • that handles GET requests made on /student.
  • with return type: ResponseEntity<Student>.
  • named getStudent.
  • that accepts a @PathVariable Long id.
  • that returns a ResponseEntity with no data and a status of 200.

Postman

Inside Postman, create a collection called: Grade Requests.

Screen Shot 2022-08-18 at 3.07.18 AM.png

Screen Shot 2022-07-21 at 11.33.03 PM.png

Inside Grade Requests, create a request called Read Student.

Screen Shot 2022-07-21 at 11.36.09 PM.png

Make a GET request to localhost:8080/student/1

Screen Shot 2022-07-21 at 11.37.24 PM.png

POST Request

Create a method:

  • that handles POST requests made on /student.
  • with return type ResponseEntity<Student>
  • named saveStudent
  • that deserializes incoming JSON properties into a Student object.
  • that returns a ResponseEntity which re-serializes the object into a JSON with a status code of 201.

Postman

  • Create a request called Create Student.
  • Make a POST request that sends the following JSON:
{ "name": "Harry Potter", "birthDate": "1980-07-31" }

Response: 201 Created

{ "id": null, "name": "Harry Potter", "birthDate": "1980-07-31" }

DELETE Request

Create a method:

  • that handles DELETE requests made on /student.
  • with return type ResponseEntity<HTTPStatus>.
  • named deleteStudent.
  • with @PathVariable Long id.
  • returns a ResponseEntity with a status code of 204.

Postman

  • Create a request called Delete Student.

  • Make a DELETE request.

Response: 204 No Content.

GET Request

  • method handles GET requests made on /student/all.
  • return type: ResponseEntity<List<Student>>.
  • name: getStudents.
  • returns a ResponseEntity with a status code of 200.

Postman

  • Create a request called Read Students.

  • Make a GET request.

Response: 200 OK.

Final Touches

Save every request

Screen Shot 2022-07-22 at 1.28.29 AM.png

Create a new folder called Student. Drag every Student request there.

Screen Shot 2022-07-27 at 11.45.13 PM.png

Good Luck!

Feedback Summary
5.0
3 students
5

100%
4

0%
3

0%
2

0%
1

0%
Written Reviews
There are no written reviews yet.