0
0
Rest APIprogramming~15 mins

Avoiding verbs in URLs in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
Avoiding verbs in URLs
📖 Scenario: You are designing a simple REST API for a library system. The API should follow best practices by avoiding verbs in the URLs and instead use nouns to represent resources.
🎯 Goal: Build a set of REST API endpoint URLs that use nouns only, avoiding verbs, to represent actions on the library's books and authors.
📋 What You'll Learn
Create a list called resources with the exact strings: 'books' and 'authors'
Create a variable called base_url with the exact value 'https://api.library.com/'
Use a list comprehension called endpoints to create URLs for listing and detail views for each resource, following REST best practices without verbs
Print the endpoints list exactly as shown in the final output
💡 Why This Matters
🌍 Real World
APIs that follow REST principles are easier to understand and maintain. Avoiding verbs in URLs helps keep the API clean and consistent.
💼 Career
Many software development jobs require designing or working with REST APIs that follow best practices, including proper URL design.
Progress0 / 4 steps
1
Create the resource list
Create a list called resources with the exact strings 'books' and 'authors'.
Rest API
Need a hint?

Use square brackets and quotes to create the list with the exact words.

2
Set the base URL
Create a variable called base_url and set it to the exact string 'https://api.library.com/'.
Rest API
Need a hint?

Remember to include the trailing slash in the URL string.

3
Create RESTful endpoints list
Use a list comprehension called endpoints to create URLs for each resource in resources. For each resource, create two URLs: one for listing all items (e.g., https://api.library.com/books) and one for accessing a single item by ID (e.g., https://api.library.com/books/{id}). Do not use verbs in the URLs.
Rest API
Need a hint?

Use two list comprehensions combined with + to create the list of URLs.

4
Print the endpoints list
Write a print statement to display the endpoints list exactly as it is.
Rest API
Need a hint?

Use print(endpoints) to show the list.