0
0
Rest APIprogramming~30 mins

GET for reading resources in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
GET for reading resources
📖 Scenario: You are building a simple REST API server that allows users to read information about books in a library.Users will send GET requests to your API to get details about books.
🎯 Goal: Create a REST API endpoint that handles GET requests to read book information from a predefined list of books.
📋 What You'll Learn
Create a list of books with exact titles and authors
Add a variable to hold the API endpoint path
Write code to handle GET requests and return the correct book data
Print the response data to show the result of the GET request
💡 Why This Matters
🌍 Real World
APIs often provide data to users or other programs using GET requests to read resources like books, products, or users.
💼 Career
Understanding how to handle GET requests and return data is a fundamental skill for backend developers and API designers.
Progress0 / 4 steps
1
DATA SETUP: Create a list of books
Create a list called books with these exact dictionaries:
{'id': 1, 'title': '1984', 'author': 'George Orwell'},
{'id': 2, 'title': 'To Kill a Mockingbird', 'author': 'Harper Lee'},
and {'id': 3, 'title': 'The Great Gatsby', 'author': 'F. Scott Fitzgerald'}.
Rest API
Need a hint?
Remember to create a list named books with three dictionaries exactly as shown.
2
CONFIGURATION: Define the API endpoint path
Create a variable called endpoint and set it to the string "/books".
Rest API
Need a hint?
Set endpoint exactly to the string "/books".
3
CORE LOGIC: Handle GET request to return books
Write a function called get_books that takes no parameters and returns the books list.
Rest API
Need a hint?
Define a function named get_books that returns the books list.
4
OUTPUT: Print the result of the GET request
Call the function get_books() and print its result.
Rest API
Need a hint?
Use print(get_books()) to show the list of books.