0
0
Rest APIprogramming~30 mins

Batch create endpoint design in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
Batch Create Endpoint Design
📖 Scenario: You are building a simple REST API for a bookstore. The API should allow clients to add multiple new books at once using a batch create endpoint.This is useful when a bookstore wants to upload many new books in one request instead of sending many separate requests.
🎯 Goal: Create a batch create endpoint that accepts a list of books and returns a response confirming the books were added.You will design the data structure for the books, configure a helper variable for counting, implement the batch creation logic, and output the result.
📋 What You'll Learn
Create a list variable named new_books with exactly three book dictionaries.
Each book dictionary must have keys title and author with string values.
Create a variable named added_count initialized to zero.
Use a for loop with variable book to iterate over new_books.
Inside the loop, increment added_count by 1 for each book.
Print a message showing how many books were added using print().
💡 Why This Matters
🌍 Real World
Batch create endpoints are common in APIs to efficiently add many records at once, saving time and network resources.
💼 Career
Understanding batch operations is important for backend developers building scalable APIs and for frontend developers consuming such APIs.
Progress0 / 4 steps
1
Create the list of new books
Create a list called new_books with these exact dictionaries: {'title': 'The Hobbit', 'author': 'J.R.R. Tolkien'}, {'title': '1984', 'author': 'George Orwell'}, and {'title': 'To Kill a Mockingbird', 'author': 'Harper Lee'}.
Rest API
Need a hint?

Use a list with three dictionaries. Each dictionary has keys 'title' and 'author' with string values.

2
Add a counter variable
Create a variable called added_count and set it to 0 to count how many books are added.
Rest API
Need a hint?

Just create a variable named added_count and assign 0 to it.

3
Implement batch creation logic
Use a for loop with variable book to iterate over new_books. Inside the loop, increase added_count by 1 for each book.
Rest API
Need a hint?

Use a for loop: for book in new_books: and inside it add 1 to added_count.

4
Print the result
Write a print() statement that outputs exactly: "Added 3 books successfully." using the added_count variable inside an f-string.
Rest API
Need a hint?

Use print(f"Added {added_count} books successfully.") to show the result.