RESTful API for...
In this example, you'll see how to write an API in Flask and different ways to handle requests.
- Simple flask application using application factory, blueprints
- Authentication using Flask-JWT-Extended including access token and refresh token management
- Configuration using environment variables
- OpenAPI Swagger UI
This project requires the use of the Python environment, which allows us to create a consistent and isolated environment for the project. So we will install Python with Anaconda and create virtual envierment, in witch we will save our envierment variables and install specific python packeges.
- Go to the Python download page for Windows
- Click on the latest version of Python.
- Open the installer and follow the instructions. Make sure to select the Add Python to PATH option during the installation process.
- Open a terminal window.
- Enter the following command to update the package list:
sudo apt-get update
- Enter the following command to install Python:
sudo apt-get install python3
- Go to the Python download page for macOS
- Click on the latest version of Python.
- Open the installer and follow the instructions. Make sure to select the Install for all users and Add Python to PATH options during the installation process.
- Go to the Anaconda download page.
- Select the latest version of Anaconda for Python 3.x for Windows and click on the "Download" button.
- Open the downloaded executable file and follow the instructions in the Anaconda installer.
- During the installation process, you can choose whether to add Anaconda to your system path and whether to make Anaconda your default Python distribution. Choose Anaconda to your system path.
- Go to the Anaconda download page.
- Select the latest version of Anaconda for Python 3.x for Linux and click on the "Download" button.
- Open a terminal window and navigate to the directory where the Anaconda installer was downloaded.
- Use the following command to install Anaconda:
Replace [version] with the version number of the Anaconda installer you downloaded.
bash Anaconda[version]-Linux-x86_64.sh
- Follow the instructions in the Anaconda installer.
- Go to the Anaconda download page.
- Select the latest version of Anaconda for Python 3.x for macOS and click on the "Download" button.
- Open the downloaded executable file and follow the instructions in the Anaconda installer.
- During the installation process, you can choose whether to add Anaconda to your system path and whether to make Anaconda your default Python distribution. Choose Anaconda to your system path.
- Open the Terminal app.
- Navigate to the directory where you want to create the virtual environment (project directory).
- Create a new virtual environment for your project by running the command:
Replace "my_env" with the name you want to give to your virtual environment.
conda create --name my_env
- Activate the virtual environment by running the command:
Replace "my_env" with the name of your virtual environment.
conda activate my_env
- Once you're done working with your project and want to deactivate the virtual environment, you can run the command:
conda deactivate
- Activate the environment in which you want to add the environment variable. You can do this by running the following command in the terminal or command prompt:
Replace "my_env" with the name of your environment.
conda activate my_env
- Run the following command to install the packages specified in the requirements.txt file:
This will read the requirements.txt file and install all the packages listed in it.
conda install --file requirements.txt
- After the installation is complete, verify that the packages are installed by running the following command:
conda list
- Run the following command to set the environment variables:
Replace with your own path.
conda env config vars set SSL_CERTIFICATE_PATH=/path/to/directory
- Generate self signed certificate:
python self_signed_cert_generator.py