Skip to content

Create API with FastAPI & Beanie ODM for MongoDB and implement OAuth2 & JWT authentication

Notifications You must be signed in to change notification settings

iamzehan/FastAPI-Beanie-MongoDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to create FastAPI with MongoDB?


FastAPI html5 + Beanie html5 + MongoDB html5

Here's the directory structure


├── app
│   ├── __init__.py
│   ├── main.py
│   ├── auth
│   │   ├── auth_handler.py
│   │   ├── auth_token.py
│   │   └── auth_user.py
│   └── server
│       ├── app.py
│       ├── database.py
│       ├── models
│       └── routes
└── requirements.txt

Responsible for running the app on server

Handles the authentication processes.


Contains database schema and API routes.


Contains files that define the structure of your database documents. (This is a NoSQL Database so, there's no tabular schema)


Handles all the requests and responses

Screenshot 2024-01-15 001300

html5 app.py


Registers and handles urls and runs the FastAPI instance.

html5 database.py


Handles the connection with the database and as well as all the interactions between MongoDB server and the FastAPI server.

html5 Setting up the Development Environment

html5 Create Virtual Environment

virtualenv env

html5 Activate env

source env/Scripts/activate

html5 Install requirements

pip install -r requirements.txt

html5 Run the project

python app/main.py

or

$ cd app/server

$ uvicorn app:app --reload

Technologies & Links


html5 html5 html5 html5 html5 html5


Releases

No releases published

Packages

No packages published