0
0
Rest APIprogramming~10 mins

Self link for current resource 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 to the resource.

Rest API
self_link = request.url + [1]
Drag options to blanks, or click blank then click option'
A"/link"
B"/current"
C"/self"
D"/resource"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong path like '/link' or '/resource' which does not represent the self link.
2fill in blank
medium

Complete the code to return the self link in the JSON response.

Rest API
return jsonify({"self": [1])
Drag options to blanks, or click blank then click option'
Arequest.base_url
Brequest.url
Crequest.path
Drequest.host_url
Attempts:
3 left
💡 Hint
Common Mistakes
Using request.base_url which excludes query parameters.
Using request.host_url which is only the domain.
3fill in blank
hard

Fix the error in the code to correctly generate the self link.

Rest API
self_link = f"[1]/self"
Drag options to blanks, or click blank then click option'
Arequest.path
Brequest.url
Crequest.host_url
Drequest.base_url
Attempts:
3 left
💡 Hint
Common Mistakes
Using request.url which may cause duplicated query parameters.
Using request.path which is only the path, missing domain.
4fill in blank
hard

Fill both blanks to create a dictionary with the self link and resource ID.

Rest API
response = {"self": [1], "id": [2]
Drag options to blanks, or click blank then click option'
Arequest.url
Bresource_id
Drequest.path
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing request.path with the full URL.
Using wrong variable names for the resource ID.
5fill in blank
hard

Fill all three blanks to build a JSON response with self link, resource ID, and type.

Rest API
response = {"self": [1], "id": [2], "type": [3]
Drag options to blanks, or click blank then click option'
Arequest.url
Bresource_id
C"example"
Drequest.path
Attempts:
3 left
💡 Hint
Common Mistakes
Using request.path instead of full URL for self link.
Forgetting to put quotes around the type string.