0
0
Rest APIprogramming~10 mins

Why consistent formats improve usability in Rest API - Test Your Understanding

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

Complete the code to set the Content-Type header for JSON responses.

Rest API
headers = {"Content-Type": "[1]"}
Drag options to blanks, or click blank then click option'
Atext/html
Bapplication/json
Capplication/xml
Dtext/plain
Attempts:
3 left
💡 Hint
Common Mistakes
Using text/html instead of application/json causes clients to misinterpret the data.
Omitting the Content-Type header leads to inconsistent handling.
2fill in blank
medium

Complete the code to parse a JSON response body.

Rest API
data = response.[1]()
Drag options to blanks, or click blank then click option'
Ajson
Btext
Ccontent
Dhtml
Attempts:
3 left
💡 Hint
Common Mistakes
Using text() returns raw string, not parsed JSON.
Using html() or content() does not parse JSON.
3fill in blank
hard

Fix the error in the code to send a JSON payload in a POST request.

Rest API
response = requests.post(url, json=[1])
Drag options to blanks, or click blank then click option'
ANone
B'{"key": "value"}'
C{"key": "value"}
Djson.dumps({"key": "value"})
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a JSON string causes the library to send it as a string, not JSON.
Passing None results in no payload sent.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that filters JSON keys starting with 'user'.

Rest API
filtered = {key: value for key, value in data.items() if key [1] 'user'[2]
Drag options to blanks, or click blank then click option'
Astartswith
Bendswith
C==
D()
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' compares the whole string, not the start.
Forgetting parentheses causes a syntax error.
5fill in blank
hard

Fill all three blanks to create a JSON response with a consistent format including status and data.

Rest API
response = [1]({{"status": [2], "data": [3])
Drag options to blanks, or click blank then click option'
Amake_response
B"success"
Cpayload
Djsonify
Attempts:
3 left
💡 Hint
Common Mistakes
Using make_response without JSON conversion.
Passing status as a variable instead of a string.
Forgetting to pass the data dictionary.