1

I have API built with FastAPI

from fastapi import FastAPI
from typing import Optional

import uvicorn

app = FastAPI()

class User(BaseModel):
    username: str

user_list = ["John", "Abrahim", "Kiana"]

#Get method to fetch some value
@app.get('/user/{id}/')
def users(id:int):
    return user_list[id]


if __name__ == "__main__":
    uvicorn.run(app, host="127.0.0.1",port=8000)

How I can achieve Service Timeout for this API? Will be thankful for the suggestions and written example if possible.

Chris
  • 18,724
  • 6
  • 46
  • 80
Aadhi Verma
  • 172
  • 2
  • 11
  • What do you mean by "Service Timeout"? What you've shared is just a very basic FastAPI app. – M.O. Apr 27 '23 at 07:11
  • @M.O. Yeah so the api should timeout after certain seconds. Basically I want the api should return timeout error if it takes much time to send the response. – Aadhi Verma Apr 27 '23 at 07:21
  • @Chris it actually helped me. I was bit confused with the code in get method but later on realized that, it wasn’t required for my case. Thanks for helping. – Aadhi Verma May 01 '23 at 09:54

0 Answers0