0
0
Rest APIprogramming~15 mins

DELETE for removing resources in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
DELETE for Removing Resources in REST API
📖 Scenario: You are building a simple REST API for a library system. The API manages books, and you want to allow users to remove books from the collection when they are no longer available.
🎯 Goal: Build a REST API endpoint that allows deleting a book resource by its ID using the DELETE HTTP method.
📋 What You'll Learn
Create a dictionary called books with exact book entries
Add a variable book_id_to_delete to specify which book to remove
Write code to delete the book with the given ID from the books dictionary
Print the updated books dictionary after deletion
💡 Why This Matters
🌍 Real World
APIs often need to remove resources like users, products, or posts. Using DELETE requests is the standard way to do this.
💼 Career
Understanding how to remove resources safely and correctly is essential for backend developers and API designers.
Progress0 / 4 steps
1
DATA SETUP: Create the initial books dictionary
Create a dictionary called books with these exact entries: 1: 'The Hobbit', 2: '1984', 3: 'Pride and Prejudice'
Rest API
Need a hint?

Use curly braces {} to create a dictionary with keys as numbers and values as book titles.

2
CONFIGURATION: Specify the book ID to delete
Create a variable called book_id_to_delete and set it to 2 to indicate the book to remove
Rest API
Need a hint?

Just assign the number 2 to the variable book_id_to_delete.

3
CORE LOGIC: Delete the book from the dictionary
Use the del statement with books[book_id_to_delete] to remove the book with the given ID
Rest API
Need a hint?

Use del followed by the dictionary key access to remove the entry.

4
OUTPUT: Print the updated books dictionary
Write print(books) to display the dictionary after deletion
Rest API
Need a hint?

Use the print() function to show the current state of the books dictionary.