0
0
Rest APIprogramming~10 mins

Safe methods vs unsafe methods in Rest API - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to use the HTTP method that is considered safe and only retrieves data.

Rest API
response = requests.[1]('https://api.example.com/data')
Drag options to blanks, or click blank then click option'
AGET
BDELETE
CPOST
DPUT
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST or PUT when only reading data is needed.
2fill in blank
medium

Complete the code to use the HTTP method that is unsafe and used to create new data on the server.

Rest API
response = requests.[1]('https://api.example.com/data', json=payload)
Drag options to blanks, or click blank then click option'
AGET
BOPTIONS
CHEAD
DPOST
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET when data needs to be created or changed.
3fill in blank
hard

Fix the error in the code by choosing the correct HTTP method that is safe and used to check headers only.

Rest API
response = requests.[1]('https://api.example.com/data')
Drag options to blanks, or click blank then click option'
APUT
BHEAD
CPOST
DDELETE
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET when only headers are needed.
4fill in blank
hard

Fill both blanks to complete the code that uses a safe method and checks if the response status is 200.

Rest API
response = requests.[1]('https://api.example.com/data')
if response.status_code [2] 200:
    print('Success')
Drag options to blanks, or click blank then click option'
AGET
B==
C!=
DPOST
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST instead of GET for safe retrieval.
Using != instead of == for status check.
5fill in blank
hard

Fill all three blanks to complete the code that sends data with an unsafe method, checks if the response status is 201, and prints a message.

Rest API
response = requests.[1]('https://api.example.com/data', json=payload)
if response.status_code [2] 201:
    print('[3]')
Drag options to blanks, or click blank then click option'
AGET
B==
CCreated
DPOST
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST for creating data.
Checking for status 200 instead of 201.