0
0
Rest APIprogramming~10 mins

API key authentication 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 add the API key to the request headers.

Rest API
headers = {"Authorization": "[1]"}
Drag options to blanks, or click blank then click option'
A"ApiKey 12345"
B"Key 12345"
C"Token 12345"
D"Bearer 12345"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "Bearer" instead of "ApiKey" prefix.
Not including the API key in the header.
Using incorrect header names.
2fill in blank
medium

Complete the code to send a GET request with the API key in the headers using Python requests.

Rest API
response = requests.get(url, headers=[1])
Drag options to blanks, or click blank then click option'
Aauth
Bheaders
Cparams
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the API key in 'auth' or 'params' instead of 'headers'.
Not passing headers at all.
3fill in blank
hard

Fix the error in the code to correctly include the API key in the request headers.

Rest API
headers = {"Authorization": "ApiKey " + [1]
response = requests.get(url, headers=headers)
Drag options to blanks, or click blank then click option'
A"12345"
B12345
C'12345'
D"Bearer 12345"
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the API key value causing syntax errors.
Using the wrong prefix like "Bearer".
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that filters headers to only include the API key header.

Rest API
filtered_headers = {k: v for k, v in headers.items() if k [1] "Authorization" and v [2] "ApiKey 12345"}
Drag options to blanks, or click blank then click option'
A==
B!=
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using != which excludes the API key header.
Using comparison operators like > or < which don't make sense here.
5fill in blank
hard

Fill both blanks to build a dictionary comprehension that includes headers with keys starting with 'X-' and values containing 'token'.

Rest API
filtered = {k:v for k, v in headers.items() if k[1] "X-" and "token" [2] v}
Drag options to blanks, or click blank then click option'
A:
B.startswith(
Cin
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of ':' in dictionary comprehension.
Using '==' instead of 'in' for substring check.
Not using startswith() for prefix check.