This is a toy FastAPI server, demonstrating basic functionalities of it. It's also related to a series of docker challenges in my company (Tosan), in which the project should be dockerized.
- Install requirements:
- Install "python3.7"
- Install "virtualenv"
pip install virtualenv
-
Create the virtual environment using following command:
virtualenv .env
- Active virtualenv:
- For windows:
.env\Scripts\activate
- For windows:
- Now you can install libraries and dependencies listed in requirements file:
pip install -r requirements.txt
-
You can exit from virtual environment using following command:
deactivate
- Set environment variables:
- Set the path to config file:
FAST_API_TOY_SERVER_ENV=path\to\config
- Specify the port number (if you don't, it will default to 8080):
PORT_NUMBER=5000
- For development:
FAST_API_ENV=development
- For production:
FAST_API_ENV=production
- Set the path to config file:
- Run the app:
python asgi.py
-
To install and run the app locally with docker, follow these steps:
- First, build the docker image from dockerfile:
docker build -t imagetag .
- Then, create a container from the image and run it:
docker run -d --name mycontainer -p 8080:8080 myimage
- Ulternatively, you can just run the following command to automate the process:
docker-compose up
- Redoc documentation:
http://localhost:8080/redoc
- Swagger UI documentation:
http://localhost:8080/docs
-
To test the Server just run the following commands:
- For unit tests:
pytest -m unit
- For end to end tests:
pytest -m endtoend
- To check code coverage just add the below line at the end of above commands:
--cov=app\main
- For unit tests:
python -m pytest