0
0
Rest APIprogramming~10 mins

Composite operations (multi-resource) 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 send a POST request to create a new user.

Rest API
response = requests.[1]('https://api.example.com/users', json=user_data)
Drag options to blanks, or click blank then click option'
Aget
Bpost
Cdelete
Dput
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST to create a resource.
Using DELETE or PUT incorrectly for creation.
2fill in blank
medium

Complete the code to check if the response status code indicates success.

Rest API
if response.status_code == [1]:
    print('Success')
Drag options to blanks, or click blank then click option'
A200
B301
C500
D404
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 404 instead of 200.
Confusing redirect codes like 301 with success.
3fill in blank
hard

Fix the error in the code to update a user's email using PUT method.

Rest API
response = requests.[1]('https://api.example.com/users/123', json={'email': new_email})
Drag options to blanks, or click blank then click option'
Adelete
Bget
Cpost
Dput
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET or POST instead of PUT for updating.
Using DELETE which removes the resource.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps user IDs to their names for users with active status.

Rest API
active_users = {user['id']: user[1] for user in users if user['status'] [2] 'active'}
Drag options to blanks, or click blank then click option'
A['name']
B['email']
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using ['email'] instead of ['name'] for values.
Using '!=' instead of '==' in the condition.
5fill in blank
hard

Fill all three blanks to filter and map user data: keys are uppercase user names, values are emails for users older than 30.

Rest API
filtered_users = [1]({ [2]['name'].upper(): [3] for [2] in users if [2]['age'] > 30 })
Drag options to blanks, or click blank then click option'
Adict
Buser
Cuser['email']
Dusers
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'users' instead of 'user' as loop variable.
Not calling dict() around the comprehension.