0
0
Rest APIprogramming~15 mins

Batch delete patterns in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
Batch Delete Patterns with REST API
📖 Scenario: You are building a simple REST API to manage a list of tasks. Sometimes, users want to delete multiple tasks at once instead of deleting them one by one.Batch deleting helps users save time by removing many tasks in a single request.
🎯 Goal: Build a REST API endpoint that accepts a list of task IDs and deletes all those tasks in one batch operation.You will create the initial data, set up a list of IDs to delete, write the batch delete logic, and finally show the remaining tasks.
📋 What You'll Learn
Create a dictionary called tasks with these exact entries: 1: 'Buy groceries', 2: 'Clean room', 3: 'Pay bills', 4: 'Call mom', 5: 'Read book'
Create a list called delete_ids with these exact values: 2, 4
Use a for loop with variable task_id to iterate over delete_ids and delete each task_id from tasks if it exists
Print the tasks dictionary after deletion to show remaining tasks
💡 Why This Matters
🌍 Real World
Batch deleting is common in apps like email clients, to-do lists, or file managers where users want to remove many items quickly.
💼 Career
Understanding batch operations and safe deletion is important for backend developers building efficient and user-friendly APIs.
Progress0 / 4 steps
1
Create the initial tasks dictionary
Create a dictionary called tasks with these exact entries: 1: 'Buy groceries', 2: 'Clean room', 3: 'Pay bills', 4: 'Call mom', 5: 'Read book'
Rest API
Need a hint?

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

2
Set up the list of task IDs to delete
Create a list called delete_ids with these exact values: 2, 4
Rest API
Need a hint?

Use square brackets [] to create a list with the numbers 2 and 4.

3
Write the batch delete logic
Use a for loop with variable task_id to iterate over delete_ids and delete each task_id from tasks if it exists
Rest API
Need a hint?

Use del tasks[task_id] inside the loop to remove the task if it exists.

4
Print the remaining tasks
Write print(tasks) to display the tasks dictionary after deletion
Rest API
Need a hint?

Use print(tasks) to show the dictionary after deletion.