0
0
Rest APIprogramming~10 mins

Header-based versioning 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 read the API version from the custom header.

Rest API
version = request.headers.get('[1]')
Drag options to blanks, or click blank then click option'
AAuthorization
BContent-Type
CAccept
DX-API-Version
Attempts:
3 left
💡 Hint
Common Mistakes
Using standard headers like 'Content-Type' or 'Accept' instead of a custom version header.
2fill in blank
medium

Complete the code to check if the API version is 'v2'.

Rest API
if version == '[1]':
    process_v2_request()
Drag options to blanks, or click blank then click option'
Av2
Bversion2
C2.0
Dversion_2
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'version2' or '2.0' which are not the standard version strings.
3fill in blank
hard

Fix the error in the code to correctly extract the version from headers.

Rest API
api_version = request.headers['[1]']
Drag options to blanks, or click blank then click option'
AX-API-Version
BAccept-Version
CVersion
DApi-Version
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect header names like 'Version' or 'Api-Version' which do not exist.
4fill in blank
hard

Fill both blanks to create a response that varies based on the API version header.

Rest API
if request.headers.get('[1]') == 'v1':
    return [2]('Response for version 1')
Drag options to blanks, or click blank then click option'
AX-API-Version
Bmake_response
Cjsonify
DResponse
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect header names or response functions that do not return JSON.
5fill in blank
hard

Fill all three blanks to implement header-based versioning with default fallback.

Rest API
version = request.headers.get('[1]', '[2]')
if version == 'v1':
    return [3]({'message': 'Version 1 response'})
Drag options to blanks, or click blank then click option'
AX-API-Version
Bv1
Cjsonify
Dmake_response
Attempts:
3 left
💡 Hint
Common Mistakes
Not providing a default version or using wrong response functions.