This is a sample FastAPI application that interacts with a MongoDB database.
-
Clone this repository:
git clone https://github.com/vivek378521/fastapi-mongo.git -
Create a virtual environment:
python3 -m venv envI have used python3.9 for building this app, so if you have python version <3.7 you might face some issues -
Activate the virtual environment:
source env/bin/activate -
Install the requirements:
pip install -r requirements.txt -
Importing Data Before running the application, you'll need to import some sample data into your MongoDB database. To do this, run the import_data.py script:
python import_data.pyThis script will create a new database named kimo and import some sample data into a collection named courses. -
Running the Tests To run the unit tests, run the pytest command:
pytest courses_test.pyThese tests assume that the MongoDB database is running on the default port (27017) on the same machine as the application. -
Running the Application To run the FastAPI application, use the uvicorn command:
uvicorn server:app --reloadThis will start the application on http://localhost:8000.
To view the API documentation, navigate to http://localhost:8000/docs in your web browser. This page is automatically generated by FastAPI and provides detailed documentation for all of the API endpoints.