I want to make a discord bot that would work with data that would be sent from a web application via POST request. So for that I need to make my own API containing that POST request with FastAPI.
My question is: how can make my API work with the rest of the code?
Consider this example:
from fastapi import FastAPI, Request
from pydantic import BaseModel
app = FastAPI()
dict = {"name": "","description": ""}
class Item(BaseModel):
name: str
description: str
@app.post("/item")
async def create_item(request: Request, item: Item):
result = await request.json()
dict["name"] = result["name"]
print(dict)
print(dict)
When I run the API, type the values in and print dict
for the fist time, it outputs something like that: {'name': 'some_name', 'desc': 'some_desc'}
But when I run my file as python code, only {'name': '', 'desc': ''}
gets printed out.
I thought that after I type in values in dict
on my API page (https://localhost:800/docs), python would output the exact values I typed, but it didn't happen.
What do I do?