This is a fastapi application backed by Postgresql database.
This application stored the posts created by multiple users and the votes/likes they have given to each of the posts.
The api in response provides a detailed information about the post contents, the owner/user who created the post and the votes/likes it has been given.
Please follow the steps to run the application successfully.
- Clone the repository using the below command.
git clone https://github.com/Anu1996rag/fastapi.git
- Create a virtual environment
python3 -m venv <virtual_environment_name>
- Activate the virtual environment
source /<virtual_environment_name>/bin/activate
- Use the package manager pip to install the requirements.
pip install -r requirements.txt
- Run the server using the below command.
uvicorn app.main:app
- Make sure the postgresql service is installed in your system and it is running by running the following command.
sudo /etc/init.d/postgresql status
- To start it you can issue the command
sudo /etc/init.d/postgresql start
- To stop you can issue the command
sudo /etc/init.d/postgresql-8.3 stop
- If you are using poetry, follow the below set of commands.
poetry shell
poetry install
poetry run uvicorn app.main:app
- You should see the below response
INFO 2022-11-16 11:30:28.782 | uvicorn.server:serve | Started server process [17055]
INFO 2022-11-16 11:30:28.783 | uvicorn.lifespan.on:startup | Waiting for application startup.
INFO 2022-11-16 11:30:28.783 | uvicorn.lifespan.on:startup | Application startup complete.
INFO 2022-11-16 11:30:28.784 | uvicorn.server:_log_started_message | Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
Use below command to run the tests
pytest -v
To access the API documentation, use the URL http://127.0.0.1:8000/docs#
You can also pull the docker image using the below command.
Make sure you have the docker installed in your system.
docker pull anurag1996/fastapi-postgres
Check logs for the api using below command
docker logs <container_id> --tail N