A good practice is to start with something simple, where we don't risk having issues in our code—so we can test the framework, first. Let's start with a simple hello world application.
Let's dive in and start with a simple hello world-style application that will return the predefined values, with no computations at all:
- First, we will need to import the library and initialize the main application object:
from fastapi import FastAPI
app = FastAPI()
- Next, let's define our toy database:
db = {'noise': 24,
'broken hydrant': 2}
- We now define the function that will be executed for each URL request and return the value:
def complaints(complaint_type: str, hour:int) -> dict:...
return {"complaint_type": complaint_type, "hour": hour, "q": db.get(complaint_type, None)}