Workbook 9.3
The grade-submission
API will serve as a mediator between a consumer and the resources in an SQL database.
Workbook 9.3 will prepare the REST endpoints for the CourseController
.
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);
}
Postman
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
Create a new folder called Course. Drag every Course
request there.
We're all set. Now we can start communicating with an SQL database.
Feedback Summary
5.0
4 students
5
100%
4
0%
3
0%
2
0%
1
0%
Written Reviews
There are no written reviews yet.