From the course: Advanced Python: Practical Database Examples
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Build a POST endpoint with FastAPI - Python Tutorial
From the course: Advanced Python: Practical Database Examples
Build a POST endpoint with FastAPI
- [Instructor] Let's implement the POST endpoint so the client can add a book to our database. The route is book, so we'll add that with the POST method. When the user sends data to this route we'll want to run a function that adds data to the database. The input to this function will be data that the user sends as a part of the request payload. We'll make this the BookAuthorPayLoad data type. In order to use this type we'll need to define it in our application. We'll do that in a separate file called schemas. We'll call it schemas.py, and this will be in the same folder as our main.py. Inside of here, we'll define the BookButhorPayLoad. It'll contain a book and an author. Now let's define the book and the author. Since this payload uses them we'll place them above the payload in our file. The book will have a title as a string and number of pages as an int. The author will have a first_name and a last_name. Both of these…
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
-
-
-
-