Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/markqiu/fastapi-mongodb-realworld-example-app
Backend logic implementation for https://github.com/gothinkster/realworld with awesome FastAPI
https://github.com/markqiu/fastapi-mongodb-realworld-example-app
Last synced: 12 days ago
JSON representation
Backend logic implementation for https://github.com/gothinkster/realworld with awesome FastAPI
- Host: GitHub
- URL: https://github.com/markqiu/fastapi-mongodb-realworld-example-app
- Owner: markqiu
- License: mit
- Fork: true (nsidnev/fastapi-realworld-example-app)
- Created: 2019-06-08T07:20:22.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-10-05T07:45:13.000Z (about 2 years ago)
- Last Synced: 2024-08-01T00:43:09.875Z (3 months ago)
- Language: Python
- Homepage: https://fastapi-realworld-example-app.herokuapp.com/docs
- Size: 132 KB
- Stars: 432
- Watchers: 10
- Forks: 93
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
- awesome-fastapi - RealWorld Example App - mongo
- awesome-fastapi - RealWorld Example App - mongo
README
.. image:: logo.png
|
.. image:: https://circleci.com/gh/nsidnev/fastapi-realworld-example-app.svg?style=svg
:target: https://circleci.com/gh/markqiu/fastapi-realworld-example-app.. image:: https://travis-ci.org/nsidnev/fastapi-realworld-example-app.svg?branch=master
:target: https://travis-ci.org/markqiu/fastapi-realworld-example-app.. image:: https://img.shields.io/github/license/Naereen/StrapDown.js.svg
:target: https://github.com/markqiu/fastapi-realworld-example-app/blob/master/LICENSE.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/blackWhat for
----------
This project is a realworld backend based on fastapi+mongodb. It can be used as a sample backend or a sample fastapi project with mongodb.Quickstart
----------First, set environment variables and create database. For example using ``docker``: ::
export MONGO_DB=rwdb MONGO_PORT=5432 MONGO_USER=MONGO MONGO_PASSWORD=MONGO
docker run --name mongodb --rm -e MONGO_USER="$MONGO_USER" -e MONGO_PASSWORD="$MONGO_PASSWORD" -e MONGO_DB="$MONGO_DB" MONGO
export MONGO_HOST=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' pgdb)
mongo --host=$MONGO_HOST --port=$MONGO_PORT --username=$MONGO_USER $MONGO_DBThen run the following commands to bootstrap your environment with ``poetry``: ::
git clone https://github.com/markqiu/fastapi-realworld-example-app
cd fastapi-realworld-example-app
poetry install
poetry shellThen create ``.env`` file (or rename and modify ``.env.example``) in project root and set environment variables for application: ::
touch .env
echo "PROJECT_NAME=FastAPI RealWorld Application Example" >> .env
echo DATABASE_URL=mongo://$MONGO_USER:$MONGO_PASSWORD@$MONGO_HOST:$MONGO_PORT/$MONGO_DB >> .env
echo SECRET_KEY=$(openssl rand -hex 32) >> .env
echo ALLOWED_HOSTS='"127.0.0.1", "localhost"' >> .envTo run the web application in debug use::
uvicorn app.main:app --reload
Deployment with Docker
----------------------You must have ``docker`` and ``docker-compose`` tools installed to work with material in this section.
First, create ``.env`` file like in `Quickstart` section or modify ``.env.example``. ``MONGO_HOST`` must be specified as `db` or modified in ``docker-compose.yml`` also. Then just run::docker-compose up -d
Application will be available on ``localhost`` or ``127.0.0.1`` in your browser.
Web routes
----------All routes are available on ``/docs`` or ``/redoc`` paths with Swagger or ReDoc.
Project structure
-----------------Files related to application are in the ``app`` directory. ``alembic`` is directory with sql migrations.
Application parts are:::
models - pydantic models that used in crud or handlers
crud - CRUD for types from models (create new user/article/comment, check if user is followed by another, etc)
db - db specific utils
core - some general components (jwt, security, configuration)
api - handlers for routes
main.py - FastAPI application instance, CORS configuration and api router includingTodo
----
1) Add more unit test