0
0
Rest APIprogramming~15 mins

Self link for current resource in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
Creating a Self Link for Current Resource in REST API
📖 Scenario: You are building a simple REST API that returns information about books. Each book resource should include a self link that points to its own URL. This helps clients know where to find or update the book.
🎯 Goal: Build a REST API response that includes a self link for the current book resource.
📋 What You'll Learn
Create a dictionary called book with keys id, title, and author with exact values
Create a variable called base_url with the exact string "http://api.example.com/books"
Add a self key to the book dictionary with the value as the full URL to the current book using base_url and book["id"]
Print the book dictionary
💡 Why This Matters
🌍 Real World
APIs often include self links so clients can easily find the URL to the current resource for reading or updating.
💼 Career
Understanding how to build self links is important for backend developers creating REST APIs and for frontend developers consuming them.
Progress0 / 4 steps
1
Create the book data dictionary
Create a dictionary called book with these exact entries: 'id': 42, 'title': 'The Art of REST', and 'author': 'Jane Doe'.
Rest API
Need a hint?

Use curly braces to create a dictionary and separate keys and values with colons.

2
Create the base URL variable
Create a variable called base_url and set it to the string "http://api.example.com/books".
Rest API
Need a hint?

Use double quotes for the string and assign it to base_url.

3
Add the self link to the book dictionary
Add a new key 'self' to the book dictionary. Its value should be the full URL string combining base_url, a slash, and the book's id. Use an f-string for this.
Rest API
Need a hint?

Use an f-string to combine base_url and book['id'] with a slash.

4
Print the book dictionary with self link
Write a print statement to display the book dictionary.
Rest API
Need a hint?

Use print(book) to show the dictionary with the self link.