Below are the 2 files that host the api and another that consumes api.
In host api, I have hosted the api with the design shown below
However, In consume api, I have added a value called 9. But this should be reflected in http://127.0.0.1:5049/randoms/
But this is not the case. Can anyone help me what wrong I am doing here
host_api.py (Hosting api)
from fastapi import FastAPI
from pydantic import BaseModel
from typing import List
import uvicorn
import random
app = FastAPI()
# Define a data model
class Item(BaseModel):
ids: int
name: str
price: float
description: str = None
rn = []
@app.post("/randoms/", response_model=rn)
def get_random(rv):
rn.append(rv)
@app.get("/randoms/", response_model=list(rn))
def read_rn():
return rn
consume_api.py
import requests
base_url = "http://127.0.0.1:5049"
response = requests.post(f"{base_url}/randoms/",data=9)