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.
Create an API contract - Python Tutorial
From the course: Advanced Python: Practical Database Examples
Create an API contract
- When a client wants to put a new piece of data into our books database, they'll use our API. Currently, our API only has a hello world type endpoint where the client runs a get request to the home route. We need to add a new endpoint that allows the client to add a book to our database. GET is a type of HTTP method used with REST APIs. It's used to request information. Other types of HTTP methods also exist such as POST, PUT, DELETE, PATCH, and a few others. In this chapter, we'll be focusing on POST. When a POST request is made to an API, typically it creates a new resource. In our case, it will create a new book and add it to our database. For the POST endpoint, we need to create a contract for how the client will send us the data. The client will send a POST request to the book endpoint or the book route. In the request, the client will also send a request payload. That's data sent with the request. This payload…
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
-
-
-
-