0
0
Rest APIprogramming~10 mins

HEAD and OPTIONS 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 define a HEAD method handler that returns headers without a body.

Rest API
def handle_request(request):
    if request.method == '[1]':
        return get_headers_only()
    else:
        return get_full_response()
Drag options to blanks, or click blank then click option'
APOST
BGET
COPTIONS
DHEAD
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of HEAD for header-only requests.
2fill in blank
medium

Complete the code to respond to an OPTIONS request with allowed methods.

Rest API
def handle_request(request):
    if request.method == 'OPTIONS':
        return {'Allow': '[1]'}
    else:
        return process_request(request)
Drag options to blanks, or click blank then click option'
A'GET, POST, OPTIONS'
B'GET, POST'
C'HEAD, OPTIONS'
D'POST, PUT'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting OPTIONS from the Allow header.
3fill in blank
hard

Fix the error in the code to correctly handle HEAD requests by removing the response body.

Rest API
def handle_head(request):
    response = get_full_response()
    if request.method == '[1]':
        response.body = None
    return response
Drag options to blanks, or click blank then click option'
AHEAD
BPOST
CGET
DPUT
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of HEAD in the condition.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps HTTP methods to their descriptions for OPTIONS response.

Rest API
methods_info = {method: '[1]' for method in ['GET', 'POST', 'HEAD', 'OPTIONS'] if method [2] 'OPTIONS'}
Drag options to blanks, or click blank then click option'
Asupported
B!=
C==
Dallowed
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' in the condition.
5fill in blank
hard

Fill all three blanks to build a response dictionary for OPTIONS method with method names, descriptions, and a flag.

Rest API
response = {
    '[1]': [method for method in allowed_methods],
    '[2]': {method: '[3]' for method in allowed_methods}
}
Drag options to blanks, or click blank then click option'
Amethods
Bdescriptions
Cactive
Dsupported
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect keys that don't match the response structure.