Spring Boot Bootcamp – Workbooks and Challenges

Workbook 9.3

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.3 will prepare the REST endpoints for the CourseController.

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

Rest Controller

The operations in CourseController are identical to the ones in StudentController. Copy the code below and perform the necessary imports.

@GetMapping("/{id}") public ResponseEntity<Course> getCourse(@PathVariable Long id) { return new ResponseEntity<>(HttpStatus.OK); } @PostMapping public ResponseEntity<Course> saveCourse(@RequestBody Course course) { return new ResponseEntity<>(course, HttpStatus.CREATED); } @DeleteMapping("/{id}") public ResponseEntity<HttpStatus> deleteCourse(@PathVariable Long id) { return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @GetMapping("/all") public ResponseEntity<List<Course>> getCourses() { return new ResponseEntity<>(HttpStatus.OK); }


Request 1

  • Create a request called Read Course.
  • Make a GET request to localhost:8080/course/1.

Response: 200 OK

Request 2

  • Create a request called Create Course.
  • Make a POST request that sends the following JSON:
{ "subject": "Potions", "code": "POT-1123", "description": "In this class, students learn the correct way to brew potions." }

Response: 201 Created

{ "id": null, "subject": "Potions", "code": "POT-1123", "description": "In this class, students learn the correct way to brew potions." }

Request 3

  • Create a request called Delete Course.
  • Test your DELETE request.

Request 4

  • Create a request called Read Courses.
  • Test your GET request.

Final Touches

Save every request

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

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

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

We're all set. Now we can start communicating with an SQL database.

Feedback Summary
4 students





Written Reviews
There are no written reviews yet.