Web Programming
-
Here we have two problems to solve
- Web serving html pages => Web APP
- Frameworks: Django
- Web serving data/actions/method => APIs
- Frameworks:
- FastAPI
- Flask
- Django-restful
- Frameworks:
- Web serving html pages => Web APP
-
our focus: APIs with FastAPI
Lets use a calculator which is hosted as api
- Instructions to run an api server on your system
git clone https://github.com/asquarezone/Python.git
cd Python/Aug26/WebAPIs/using_apis/calc
python -m venv .venv
.venv/Scripts/activate
# source .venv/bin/activate
pip install -r requirements.txt
#python main.py
fastapi dev main.py
-
Naviagate to
http://127.0.0.1:8000/docs -
This api has add, sub, mul, div
-
access add
http://127.0.0.1/add?a=3&b=5- url: http://127.0.0.1/add
- parameters:
- query string: starts with
?<name1>=<value1>&<name2>=<value2>&
- query string: starts with
-
Install postman app and use as it is recommened in the class
-
Lets write a client in python which does this
-
Create a new virtual environment
- Create a file called as
calc_client.py - Refer Here for changes done
Lets use some existing apis
- Lets get all the products: Refer Here
-
Refer Here for changes.
