0
0
Rest APIprogramming~10 mins

Related resource links 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 a related resource link in the HTTP header.

Rest API
response.headers['[1]'] = '<https://api.example.com/users>; rel="users"'
Drag options to blanks, or click blank then click option'
AAuthorization
BContent-Type
CLink
DAccept
Attempts:
3 left
💡 Hint
Common Mistakes
Using Content-Type instead of Link header
Using Authorization header for links
2fill in blank
medium

Complete the code to parse the 'Link' header and extract the URL with rel='next'.

Rest API
next_url = None
links = response.headers.get('Link', '').split(',')
for link in links:
    if 'rel=[1]' in link:
        next_url = link.split(';')[0].strip('<> ')
        break
Drag options to blanks, or click blank then click option'
A"next"
B"prev"
C"self"
D"related"
Attempts:
3 left
💡 Hint
Common Mistakes
Searching for rel="prev" instead of rel="next"
Not stripping the angle brackets from the URL
3fill in blank
hard

Fix the error in the code that builds a Link header with multiple related resources.

Rest API
link_header = ', '.join([f'<{url}>; rel=[1]' for url in urls])
response.headers['Link'] = link_header
Drag options to blanks, or click blank then click option'
A"self"
B"next"
C"prev"
D"related"
Attempts:
3 left
💡 Hint
Common Mistakes
Using rel="next" when linking multiple unrelated resources
Forgetting to join links with commas
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps resource names to their URLs from a list of tuples.

Rest API
related_links = [1]([2]: url for url, [2] in resources)
Drag options to blanks, or click blank then click option'
Adict
Bname
Curl
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using list instead of dict
Swapping url and name variables
5fill in blank
hard

Fill all three blanks to filter related links with rel='related' and extract their URLs.

Rest API
related_urls = [link.split(';')[0].strip('<>') for link in response.headers.get('[1]', '').split(',') if '[2]' in link and link.split('rel=')[1].strip('"') == [3]]
Drag options to blanks, or click blank then click option'
ALink
Brel=related
C"related"
DContent-Type
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong header name like Content-Type
Not checking the rel value correctly