0
0
Rest APIprogramming~10 mins

Request headers (Content-Type, Accept) 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 set the Content-Type header to JSON.

Rest API
headers = {"Content-Type": "[1]"}
Drag options to blanks, or click blank then click option'
Atext/html
Bapplication/json
Cimage/png
Dapplication/xml
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text/html' instead of 'application/json' for JSON data.
Leaving the Content-Type header empty.
2fill in blank
medium

Complete the code to set the Accept header to expect JSON response.

Rest API
headers = {"Accept": "[1]"}
Drag options to blanks, or click blank then click option'
Aapplication/json
Btext/plain
Ctext/html
Dapplication/xml
Attempts:
3 left
💡 Hint
Common Mistakes
Setting Accept to 'text/html' when expecting JSON.
Not setting the Accept header at all.
3fill in blank
hard

Fix the error in the header key to correctly specify Content-Type.

Rest API
headers = {"[1]": "application/json"}
Drag options to blanks, or click blank then click option'
AContent-Type
Bcontent-type
CContentType
DcontentType
Attempts:
3 left
💡 Hint
Common Mistakes
Using camelCase like 'contentType' or 'ContentType'.
Using all lowercase without hyphen.
4fill in blank
hard

Fill both blanks to set headers for sending JSON and expecting JSON response.

Rest API
headers = {"[1]": "application/json", "[2]": "application/json"}
Drag options to blanks, or click blank then click option'
AContent-Type
BAccept
CAuthorization
DUser-Agent
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up header names like using 'Authorization' or 'User-Agent'.
Using the same header name twice.
5fill in blank
hard

Fill all three blanks to create headers with Content-Type JSON, Accept JSON, and a custom header X-API-Key.

Rest API
headers = {"[1]": "application/json", "[2]": "application/json", "[3]": "12345"}
Drag options to blanks, or click blank then click option'
AContent-Type
BAccept
CX-API-Key
DAuthorization
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Authorization' instead of 'X-API-Key' for the custom header.
Forgetting to set Accept header.