A REST API of fridges with various foods like fruits built with Flask using Python.
Built from the Backend (Rest APIs and FLASK) Workshop by @lucentfong for @HackRU.
- Setup your files. You can follow along with an online environment using binder or locally by cloning/forking/downloading this repository.
- Build a new virtual environment. Open a terminal (For binder: File > New > Terminal) and use commands like
virtualenv venv --python=python3
orpython -m venv venv
(may bepython3
for unix). You should see avenv
folder generated. - Activate your virtual environment. On Windows I use
source venv\\Scripts\\activate
, another option issource venv/bin/activate
(use this one on binder). You should see(venv)
before your terminal prompt once activated successfully. - Install required dependencies. You can simply use
pip install -r requirements.txt
(may bepip3
for unix). If you want to do so manually instead, dopip install flask
for the API andpip install requests
for the API requests script. - Run the flask server. You can do this by running the command
flask run
. - Run api_test.py. Open another terminal and run
python api_test.py
(may bepython3
for unix).
You should be able to see the requests run with outputs on both terminals! 🎉
Here is a demo going through all the steps on binder:
Feel free to change values within app.py
and api_test.py
.
app.py
- Flask API server, can be ran with commandflask run
.api_test.py
- Various HTTP requests using therequests
module to test the local flask server endpoints. You can also instead use Postman or Thunder Client on VSCode.requirements.txt
- can be used with commandpip install -r requirements.txt
to install all virtual environment dependencies (run this command after activating your virtual environment). You can instead solely installflask
for the server.
For the Flask server:
flask
For the API testing script:
requests