'Fast API Python add parameter

I have a simple incoming post request to my fast api app.

async def post(request: Request): 
 ... do something

I want to call a function and initialize a variable with content from the header when the request comes in and use it then inside the function. An idea was to use the decorator but maybe I am not family enough with python, I don't get it work. What I want is something like that, does anyone know if this is possible?

class SimpleHandler:
  def __init__(self, text):
    self.text = text

  def say_hello():
    return self.text


def getHandler(header):
  return SimpleHandler(header.header_attribute)

@app.post("/")
async def get_body(request: Request, simple_handler: getHandler(header)):
  result = simple_handler.say_hello()
  ...
  return result


Solution 1:[1]

simple_handler:str = Depends(getHandler)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ashkan Goleh Pour