Using the FastAPI API
00:00
Using the FastAPI API. uvicorn
will have been installed when installing FastAPI so you can run the command seen on screen to start up a development server.
00:15 The server is now running, so open up a browser and go to the address seen on screen. Fast API responds with a JSON array containing the list of countries.
00:28
You can also add a new country by sending a POST request to /countries
.
00:56
You can also confirm this by refreshing the view of the page in the browser or revisiting the /countries
endpoint. If the data provided to the POST endpoint doesn’t match, then FastAPI will return an error.
01:10 You can try this out by making a request with JSON that doesn’t match the Pydantic model.
01:32
The JSON in this request was missing a value for area
, so Fast API returned a response with the status code 422 Unprocessable Entity
as well as details about the error.
01:43 This validation is made possible by the Pydantic model. Note also that the summary of the error will be shown on the window where you are running the FastAPI test server.
01:56 This example only scratches the surface of what FastAPI can do. With its high performance, modern features like async functions and automatic documentation, FastAPI is worth considering for your next REST API.
02:10 In the next section of the course, you’ll take a look back at what you’ve learned.
Become a Member to join the conversation.