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

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