← QCE Digital Solutions Unit 4

HTTP methods in a REST API

HTTP methods in a REST API: GET reads a resource, POST creates one, PUT updates one and DELETE removes one. The server replies with a status code such as 200 OK or 404 Not Found.

Understanding HTTP methods in a REST API in QCE Digital Solutions Unit 4

What it does: POST sends new data to create a resource, and 201 Created is the status code that confirms the new resource was made. GET reads a resource. It should not change any data on the server. PUT updates a resource, for example changing a student's email. DELETE is the method that removes it. 200 OK means success. 404 Not Found is the code for a missing resource. 404 Not Found tells the client that the requested resource does not exist.

Common mistakes: The program wants to read the list of pets, so it needs GET. DELETE removes a resource. The line should be r = requests.get(url). 404 means Not Found. A successful POST that creates a resource returns 201 Created, so the check should be r.status_code == 201.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 89–125) and word search (Modules 17–125).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Your app needs to fetch a list of students from a REST API without changing anything. Which HTTP method should it use?
GETDELETE
Matches
requests.get(url, json=new_student) # to create a student
↓
GET only reads data, so it cannot create a resource. Use POST to create a new student.
Applying
Meanings
Term
GET, POST, PUT, DELETE
Meaning
HTTP methods in a REST API: GET reads a resource, POST creates one, PUT updates one and DELETE removes one. The server replies with a status code such as 200 OK or 404 Not Found.
Practice
GET /students/7 -> 200 OK
Testing
Gaps
r = requests.(url)
Check Answer
Spots
2url = "https://x.com/pets"
3r = requests.delete(url)

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Puffin' badge — Definition Diver, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Your app needs to fetch a list of students from a REST API without changing anything. Which HTTP method should it use?
A. DELETE
B. GET ✓
GET reads a resource. It should not change any data on the server.
2. A student submits a sign-up form to add a new user account to the server. Which method fits best?
A. POST creates a new resource ✓
B. GET creates a new resource
POST is used to create a new resource. GET only reads data.
3. Which statement about PUT is correct?
A. PUT updates an existing resource ✓
B. PUT removes an existing resource
PUT updates a resource, for example changing a student's email. DELETE is the method that removes it.
4. A user closes their account, so the app asks the server to remove their record. Which method is used?
A. DELETE ✓
B. PUT
DELETE removes a resource from the server.
5. Which request reads the data for the student with ID 7?
A. POST /students/7
B. GET /students/7 ✓
GET reads the resource. POST would try to create a new one instead of reading.

Match the Pairs

requests.get("https://api.school.com/students/7") → Reads (retrieves) the student with ID 7 without changing anything on the server
requests.delete("https://api.school.com/students/7") → Removes the student with ID 7 from the server
POST creates a new resource, and the server replies 201 Created when it succeeds → requests.post(url, json=new_student) # 201
PUT updates an existing resource, and a 404 Not Found reply means that resource does not exist → requests.put(url, json=changes) # 404
requests.get(url, json=new_student) # to create a student → GET only reads data, so it cannot create a resource. Use POST to create a new student.
requests.post(url) # to delete student 7 → POST creates resources and does not delete them. Use DELETE to remove student 7.

Key Term

GET, POST, PUT, DELETE
HTTP methods in a REST API: GET reads a resource, POST creates one, PUT updates one and DELETE removes one. The server replies with a status code such as 200 OK or 404 Not Found.

Fill in the Blanks

1. url = "https://api.example.com/students" r = requests.get(url) print(r.status_code)
Hint: Type the requests function that reads a resource without changing it.
2. url = "https://api.example.com/students" r = requests.post(url, json=new_student)
Hint: Type the requests function that creates a new resource on the server.
3. url = "https://api.example.com/students/1" r = requests.put(url, json=changes)
Hint: Type the requests function that updates an existing resource.
4. url = "https://api.example.com/students/1" r = requests.delete(url)
Hint: Type the requests function that removes a resource from the server.
5. r = requests.get(url) if r.status_code == 404: print("Student not found")
Hint: Type the name of the response attribute that holds the server's status code.

Spot the Error

Question 1
A # Read the list of pets
B url = "https://x.com/pets"
C r = requests.delete(url)
D print(r.json())
Line C — The program wants to read the list of pets, so it needs GET. DELETE removes a resource. The line should be r = requests.get(url).
Question 2
A r = requests.post(url, json=d)
B if r.status_code == 404:
C print("Pet created")
Line B — 404 means Not Found. A successful POST that creates a resource returns 201 Created, so the check should be r.status_code == 201.
Question 3
A url = "https://x.com/pets/7"
B d = {"name": "Max"}
C # Update pet 7
D r = requests.post(url, json=d)
Line D — POST creates a new resource. To update the existing pet 7 you use PUT, so the line should be r = requests.put(url, json=d).
Question 4
A url = "https://x.com/pets/7"
B r = requests.put(url)
C print(r.status_code)
Line B — The program is meant to remove pet 7. PUT updates a resource, while DELETE removes it. The line should be r = requests.delete(url).
Question 5
A r = requests.get(url)
B print(r.status_code)
C if r.status_code == 201:
D print(r.json())
E else:
F print("Pet not found")
Line C — 201 means Created, which is used for POST. A successful GET returns 200 OK, so the check should be r.status_code == 200.

Student with a class code? Join your class →