0
0
Rest APIprogramming~10 mins

Idempotency of methods 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 that is idempotent.

Rest API
method = "[1]"  # This method should be idempotent
Drag options to blanks, or click blank then click option'
APOST
BCONNECT
CPUT
DTRACE
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing POST because it sends data, but POST is not idempotent.
Confusing CONNECT or TRACE as idempotent methods.
2fill in blank
medium

Complete the code to specify the HTTP method that is NOT idempotent.

Rest API
method = "[1]"  # This method is generally NOT idempotent
Drag options to blanks, or click blank then click option'
AHEAD
BGET
CDELETE
DPOST
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing DELETE thinking it is not idempotent, but DELETE is idempotent.
Confusing GET as non-idempotent, but GET is idempotent.
3fill in blank
hard

Fix the error in the code to correctly check if a method is idempotent.

Rest API
def is_idempotent(method):
    return method in [1]
Drag options to blanks, or click blank then click option'
A["POST", "PATCH"]
B["GET", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE"]
C["CONNECT", "POST"]
D["POST", "PUT"]
Attempts:
3 left
💡 Hint
Common Mistakes
Including POST or PATCH in the idempotent list.
Missing some idempotent methods like DELETE or HEAD.
4fill in blank
hard

Fill both blanks to create a dictionary mapping HTTP methods to their idempotency status.

Rest API
idempotency = {
    "GET": [1],
    "POST": [2]
}
Drag options to blanks, or click blank then click option'
ATrue
BFalse
C"Yes"
D"No"
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings like "Yes" or "No" instead of boolean values.
Marking POST as idempotent.
5fill in blank
hard

Fill all three blanks to complete the function that returns if a method is idempotent or not.

Rest API
def check_idempotency(method):
    idempotent_methods = [1]
    if method [2] idempotent_methods:
        return [3]
    else:
        return False
Drag options to blanks, or click blank then click option'
A["GET", "PUT", "DELETE", "HEAD", "OPTIONS", "TRACE"]
Bin
CTrue
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of 'in' for membership check.
Returning strings instead of boolean True.