0
0
Rest APIprogramming~20 mins

Link headers for navigation in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Link Header Navigator
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this HTTP Link header parsing?
Given the HTTP Link header below, what is the value of the 'next' URL extracted?
Rest API
Link: <https://api.example.com/items?page=2>; rel="next", <https://api.example.com/items?page=5>; rel="last"
Ahttps://api.example.com/items?page=1
Bhttps://api.example.com/items?page=5
Chttps://api.example.com/items?page=2
Dhttps://api.example.com/items?page=3
Attempts:
2 left
💡 Hint
Look for the rel="next" link in the header.
🧠 Conceptual
intermediate
1:30remaining
What is the purpose of the 'rel' attribute in Link headers?
In HTTP Link headers used for navigation, what does the 'rel' attribute specify?
AIt sets the cache expiration time for the link.
BIt specifies the HTTP method to use for the link.
CIt indicates the content type of the linked resource.
DIt defines the relationship type of the linked resource to the current resource.
Attempts:
2 left
💡 Hint
Think about how the client knows what the link means.
🔧 Debug
advanced
2:00remaining
Why does this Link header cause a parsing error?
Consider this Link header: Link: rel="next", ; rel="last" Why does it cause a parsing error?
ABecause the first link is missing a semicolon before rel attribute.
BBecause the rel attribute value is not capitalized.
CBecause the URLs are not enclosed in quotes.
DBecause the Link header must have only one URL.
Attempts:
2 left
💡 Hint
Check the syntax between the URL and the rel attribute.
🚀 Application
advanced
2:30remaining
How to include multiple navigation links in a single Link header?
You want to provide 'first', 'prev', 'next', and 'last' navigation links in one HTTP Link header. Which is the correct format?
ALink: <url1>; rel="first", <url2>; rel="prev", <url3>; rel="next", <url4>; rel="last"
BLink: <url1> rel=first, <url2> rel=prev, <url3> rel=next, <url4> rel=last
CLink: <url1>; rel="first" <url2>; rel="prev" <url3>; rel="next" <url4>; rel="last"
DLink: rel="first" <url1>, rel="prev" <url2>, rel="next" <url3>, rel="last" <url4>
Attempts:
2 left
💡 Hint
Look for correct separators and syntax between links.
Predict Output
expert
3:00remaining
What is the output of this Python code parsing Link headers?
Given the Python code below that parses an HTTP Link header, what is the output printed?
Rest API
link_header = '<https://api.example.com/items?page=3>; rel="next", <https://api.example.com/items?page=1>; rel="prev"'

links = {}
for part in link_header.split(','):
    url_part, rel_part = part.strip().split(';')
    url = url_part.strip()[1:-1]
    rel = rel_part.strip().split('=')[1].strip('"')
    links[rel] = url

print(links.get('prev'))
Ahttps://api.example.com/items?page=3
Bhttps://api.example.com/items?page=1
CNone
DKeyError
Attempts:
2 left
💡 Hint
Check how the dictionary keys are assigned and what is printed.