0
0
Rest APIprogramming~10 mins

Client-server architecture in Rest API - Interactive Code Practice

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

Complete the code to specify the HTTP method used to retrieve data from a server.

Rest API
response = requests.[1]('https://api.example.com/data')
Drag options to blanks, or click blank then click option'
Aput
Bdelete
Cget
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'get' when only retrieving data.
Confusing 'put' with 'get' method.
2fill in blank
medium

Complete the code to send JSON data to the server using the correct HTTP method.

Rest API
response = requests.[1]('https://api.example.com/data', json=payload)
Drag options to blanks, or click blank then click option'
Aget
Bpost
Cdelete
Dpatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' when trying to send data.
Confusing 'delete' with 'post' method.
3fill in blank
hard

Fix the error in the code to correctly check if the server responded with a success status code.

Rest API
if response.status_code [1] 200:
    print('Success!')
Drag options to blanks, or click blank then click option'
A==
B>=
C<
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' which checks for inequality.
Using '>' or '<' which may not be precise for success check.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps endpoints to their status codes only if the status code is 200.

Rest API
status_map = {endpoint: response.[1] for endpoint, response in responses.items() if response.status_code [2] 200}
Drag options to blanks, or click blank then click option'
Astatus_code
B==
C!=
Dcontent
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'content' instead of 'status_code' for the first blank.
Using '!=' instead of '==' in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each endpoint's uppercase name to its JSON data only if the response status code is greater than 199.

Rest API
data_map = { [1]: [2] for endpoint, response in responses.items() if response.status_code [3] 199 }
Drag options to blanks, or click blank then click option'
Aendpoint.upper()
Bresponse.json()
C>
Dendpoint.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'endpoint.lower()' instead of uppercase for the key.
Using 'response.status_code' instead of 'response.json()' for the value.
Using '<' or '==' instead of '>' for the status code check.