0
0
Rest APIprogramming~10 mins

Link relations in responses 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 'self' link relation in the JSON response.

Rest API
response = {
  "_links": {
    "self": {"href": [1]
  }
}
Drag options to blanks, or click blank then click option'
A"/items"
B"/api/items/1"
C"http://example.com/api/items"
D"items/1"
Attempts:
3 left
💡 Hint
Common Mistakes
Using relative paths without leading slash
Omitting quotes around the URL
2fill in blank
medium

Complete the code to add a 'next' link relation pointing to the next page.

Rest API
response = {
  "_links": {
    "next": {"href": [1]
  }
}
Drag options to blanks, or click blank then click option'
A"/api/items?page=2"
B"/api/items?page=3"
C"/api/items?page=1"
D"/api/items?page=0"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the current page number instead of next
Using invalid page numbers
3fill in blank
hard

Fix the error in the link relation key to correctly represent the 'prev' link.

Rest API
response = {
  "_links": {
    [1]: {"href": "/api/items?page=1"}
  }
}
Drag options to blanks, or click blank then click option'
A"back"
B"previous"
C"prev"
D"before"
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-standard relation names like 'previous' or 'back'
4fill in blank
hard

Fill both blanks to add 'self' and 'related' link relations in the response.

Rest API
response = {
  "_links": {
    [1]: {"href": "/api/items/5"},
    [2]: {"href": "/api/items/5/related"}
  }
}
Drag options to blanks, or click blank then click option'
A"self"
B"related"
C"next"
D"prev"
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'next' or 'prev' with 'related'
5fill in blank
hard

Fill all three blanks to create a response with 'self', 'next', and 'prev' link relations.

Rest API
response = {
  "_links": {
    [1]: {"href": "/api/items/10"},
    [2]: {"href": "/api/items?page=11"},
    [3]: {"href": "/api/items?page=9"}
  }
}
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 'related' instead of 'prev' or 'next'