From the course: Advanced Python: Practical Database Examples
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Solution: Develop a GET endpoint with FastAPI and a Database - Python Tutorial
From the course: Advanced Python: Practical Database Examples
Solution: Develop a GET endpoint with FastAPI and a Database
(upbeat music) - [Instructor] Let's add a dynamic get endpoint to our book API application. To start off, we'll add a get route. The route will be book and then a path parameter representing the book's ID. To add a path parameter, we'll need to do some research. Let's Google path parameters in FastAPI. Here, it says we can declare the path variable using the same format as we do Python strings. We'll use two curly braces and then also use it as input to the function. Let's add that to our implementation. When someone uses this route, we'll want to run a function. We'll call it retrieve_book. For the input, we'll have book_id from the path. It'll be an int. Now in order to retrieve the book, we'll need to interact with our database. We'll call a function called get_book from our database file. We'll also pass in the book ID so it knows which book to retrieve. Let's implement this get_book function in the database…
Contents
-
-
-
What is an API?2m 45s
-
(Locked)
API frameworks in Python1m 29s
-
(Locked)
Set up FastAPI in a Python application4m 6s
-
(Locked)
Define a database schema2m 56s
-
(Locked)
Create a MySQL database3m 45s
-
(Locked)
Create an API contract2m 22s
-
(Locked)
Build a POST endpoint with FastAPI2m 27s
-
(Locked)
Call a new API using Postman3m 35s
-
(Locked)
Add data to a database in Python using SQLAlchemy4m 45s
-
(Locked)
Integrate a database with a FastAPI application3m 33s
-
(Locked)
Challenge: Develop a GET endpoint with FastAPI and a DB1m 35s
-
(Locked)
Solution: Develop a GET endpoint with FastAPI and a Database7m 22s
-
-
-
-