📖 Scenario: You are building a simple REST API for a bookstore. The API URLs should clearly show what data they represent, so users and developers can understand the API easily.
🎯 Goal: Create a set of URL strings that represent different resources in the bookstore API. These URLs should be structured to clearly communicate the meaning of the resource they point to.
📋 What You'll Learn
Create a list called urls with exact URL strings for books and authors
Add a variable called base_url to hold the main API address
Use a list comprehension to create full URLs by combining base_url with each path
Print the final list of full URLs
💡 Why This Matters
🌍 Real World
APIs use clear URL structures so developers and users can easily understand what data they can get or change.
💼 Career
Understanding URL design is important for backend developers, API designers, and anyone working with web services.
Progress0 / 4 steps
1
Create the list of URL paths
Create a list called url_paths with these exact strings: '/books', '/books/123', '/authors', '/authors/45'
Rest API
Hint
Think of url_paths as the different parts of the API you want to access.
2
Add the base URL
Create a variable called base_url and set it to the string 'https://api.bookstore.com'
Rest API
Hint
The base_url is the main address for your API.
3
Create full URLs with list comprehension
Use a list comprehension to create a new list called full_urls by adding base_url before each path in url_paths
Rest API
Hint
Use f-strings inside the list comprehension to join the base URL and each path.
4
Print the full URLs
Write a print statement to display the full_urls list
Rest API
Hint
Just print the full_urls list to see all the complete API URLs.
Practice
(1/5)
1. Why is it important for a REST API URL to have a clear and meaningful structure?
easy
A. It makes the URL longer and more complex.
B. It helps users and developers understand what data or resource the URL points to.
C. It hides the resource details from users.
D. It prevents the API from working on mobile devices.
Solution
Step 1: Understand URL purpose in REST API
The URL should clearly indicate the resource or data it represents to make it easy to use.
Step 2: Analyze the options
Only It helps users and developers understand what data or resource the URL points to. states that clear URLs help users and developers understand the resource, which is the main goal.
Final Answer:
It helps users and developers understand what data or resource the URL points to. -> Option B
Quick Check:
Meaningful URLs improve understanding = A [OK]
Hint: Clear URLs describe the resource directly [OK]