0
0
Rest APIprogramming~15 mins

Noun-based resource naming in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
Noun-based Resource Naming in REST API
📖 Scenario: You are building a simple REST API for a bookstore. The API should use noun-based resource names to represent collections and individual items.
🎯 Goal: Create a REST API endpoint structure using noun-based resource naming conventions for books and authors.
📋 What You'll Learn
Create a list called books with three book titles as strings
Create a variable called resource_name and set it to the string "books"
Use a for loop with variable book to iterate over books and create a list called book_resources with URLs in the format "/books/{book_id}" where book_id is the index starting from 1
Print each URL in book_resources on a new line
💡 Why This Matters
🌍 Real World
REST APIs use noun-based resource names to clearly represent collections and individual items, making URLs easy to understand and consistent.
💼 Career
Understanding noun-based resource naming is essential for backend developers and API designers to create clean, maintainable, and user-friendly APIs.
Progress0 / 4 steps
1
Create the books list
Create a list called books with these exact strings: "The Hobbit", "1984", and "Pride and Prejudice".
Rest API
Need a hint?

Use square brackets [] to create a list and separate items with commas.

2
Set the resource name
Create a variable called resource_name and set it to the string "books".
Rest API
Need a hint?

Use an equals sign = to assign the string "books" to the variable resource_name.

3
Create URLs for each book resource
Use a for loop with variable book and enumerate over books starting at 1 to create a list called book_resources. Each item should be a string in the format "/books/{book_id}" where book_id is the index number.
Rest API
Need a hint?

Use a list comprehension with enumerate(books, 1) to get index starting at 1 and format strings with f-strings.

4
Print the book resource URLs
Use a for loop with variable url to iterate over book_resources and print each URL on a new line.
Rest API
Need a hint?

Use a for loop to print each URL string on its own line.