fromfastapiimportFastAPI,Response,statusapp=FastAPI()tasks={"foo":"Listen to the Bar Fighters"}@app.put("/get-or-create-task/{task_id}",status_code=200)defget_or_create_task(task_id:str,response:Response):iftask_idnotintasks:tasks[task_id]="This didn't exist before"response.status_code=status.HTTP_201_CREATEDreturntasks[task_id]