Scaffolding a FastAPI application
Scaffolding is the term generally used to describe the process of creating the initial application with little or no functionality. In this section, you will build the FastAPI application and connect it to your MongoDB Atlas instance through the asynchronous MongoDB Motor
driver. Initially, you will only create a generic and minimal FastAPI application, and gradually add functionality.
You will begin by storing the secret environment data—in your case, just the MongoDB Atlas database URL—into a .env
file. These values should be always kept outside the reach of the repositories. You want to be able to connect to your MongoDB database and verify whether the connection is successful.
Creating a .env file to keep the secrets
For managing values that should be kept secret and out of the version control system, you will use an environment file (.env
). Perform the following steps to set up the environment variables and exclude them...