0
0
Rest APIprogramming~30 mins

REST constraints and principles in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding REST Constraints and Principles
📖 Scenario: You are building a simple REST API for a library system. The API should follow REST constraints and principles to manage books data.
🎯 Goal: Learn how to apply REST constraints and principles by creating a basic REST API structure with resources, stateless communication, and proper use of HTTP methods.
📋 What You'll Learn
Create a data structure to hold book information
Define a configuration variable for the API base URL
Implement RESTful routes using HTTP methods for CRUD operations
Display the list of books after operations
💡 Why This Matters
🌍 Real World
REST APIs are used to build web services that allow different software systems to communicate over the internet using standard HTTP methods.
💼 Career
Understanding REST constraints and principles is essential for backend developers, API designers, and full-stack engineers to create scalable and maintainable web services.
Progress0 / 4 steps
1
DATA SETUP: Create the initial books data
Create a dictionary called books with these exact entries: 1: {'title': '1984', 'author': 'George Orwell'}, 2: {'title': 'To Kill a Mockingbird', 'author': 'Harper Lee'}, 3: {'title': 'The Great Gatsby', 'author': 'F. Scott Fitzgerald'}
Rest API
Need a hint?

Use a dictionary with integer keys and dictionaries as values for each book.

2
CONFIGURATION: Define the API base URL
Create a variable called API_BASE_URL and set it to the string "/api/books"
Rest API
Need a hint?

Set the base URL string exactly as shown.

3
CORE LOGIC: Implement RESTful routes for GET and POST
Write a function called get_books() that returns the books dictionary, and a function called add_book(book_id, book_info) that adds a new book to books using the given book_id and book_info
Rest API
Need a hint?

Use functions to simulate REST GET and POST operations.

4
OUTPUT: Display the books after adding a new book
Call add_book(4, {'title': 'Brave New World', 'author': 'Aldous Huxley'}) and then print the result of get_books()
Rest API
Need a hint?

Call the add_book function with the new book details, then print the books dictionary using get_books.