To create a virtual environment run the below command
py -3 -m venv <name-of-your-choice>
To make sure the terminal also is using the virtual environment run the following command to activate
To install FastAPI run the following command
pip install fastapi
fastapi dev main.pyfrom fastapi import FastAPI
app = FastAPI();
@app.get("/hello")
def helloWorld():
return {"Message": "Hey hope you will enjoy the fastAPI learning"}
from fastapi import FastAPI;
app = FastAPI() #FastAPI is a class that provides all the functionality for your API
items = {
1:{
"id": "1",
"name": "glass"
},
2:{
"id": "2",
"name": "bottle"
},
3:{
"id": "3",
"name": "mic"
},
}
@app.get("/item/{itemId}")
def hello(itemId:int):
if itemId in items:
return items[itemId]
else:
return {"Message": "Item not found"}
In the above example, the value of the path parameter itemId will be passed to the function as the argument itemId.