Question: 4 . 1 Accessing JSON APIs Create a program that displays the following menu to the user: Read all students Get student by id Add

4.1 Accessing JSON APIs
Create a program that displays the following menu to the user:
Read all students
Get student by id
Add student
Edit student
Remove student
Exit
then performs the choice entered by the user.
Note: The address of the server is localhost and the port is 5000. This must be used as the base URL for all requests.
Note 2: If something is wrong with a request you send, the server will answer with 400 Bad Request.
1. Read all students
Connects to the server and send a get request to the /students/ resource.
Print information about every student returned by the server.
Expected output: id: 1, name: Kathryn Boyd, email: kathrynb@uia.no, year: 2024
2. Get student by id
Asks the user for a student id then connects to the server and send a get request to the /students/ resource.
Print information about the result returned by the server.
Expected output per status code:
200 OK
id: 1, name: Kathryn Boyd, email: kathrynb@uia.no, year: 2024
404 Not Found
Student not found
3. Add student
Asks the user for the following (in order):
Name
Email
Year
Then sends a POST request to /students/ to add the new student. The format of the data must be:
{
"name": "William Canez",
"email": "williamc@uia.no",
"year": 2006
}
And prints out the response. The server will respond with 201 Created if everything went OK.
Expected output: Added student: id: 1, name: Kathryn Boyd, email: kathrynb@uia.no, year: 2024
4. Edit student
This is very similar to add student, so I recommend solving that one first then reusing code.
Asks the user for the following (in order):
Student id
Name
Email
Year
Then sends a PUT request to /students/ to modify the existing student. The format of the data must be:
{
"id": 1,
"name": "William Canez",
"email": "williamc@uia.no",
"year": 2006
}
Expected output per status code:
200 OK if everything went OK
Student was edited successfully
404 Not Found if the student doesn't exist
Student not found
5. Remove student
Asks the user for a student id then sends a DELETE request to /students/ to remove the existing student. No data is sent.
Expected output per status code:
204 No Content if everything went OK
Student was removed successfully
404 Not Found if the student doesn't exist
Student not found
6. Exit
Exits the program.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!