Workbook 9.1
The grade-submission
API will serve as a mediator between a consumer and the resources in an SQL database.
Workbook 9.1 will prepare the REST endpoints for the StudentController
.
Launch the Starter Project
@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.
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.
Inside Grade Requests, create a request called Read Student
.
Make a GET request to localhost:8080/student/1
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
Create a new folder called Student. Drag every Student
request there.