iamzehan / FastAPI-Beanie-MongoDB

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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


About

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


Languages

Language:Python 98.4%Language:Dockerfile 1.6%