mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-24 06:39:31 -05:00
Co-authored-by: Yurii Motov <yurii.motov.monte@gmail.com> Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
16 lines
519 B
Python
16 lines
519 B
Python
from fastapi import BackgroundTasks, FastAPI
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
def write_notification(email: str, message=""):
|
|
with open("log.txt", mode="w") as email_file:
|
|
content = f"notification for {email}: {message}"
|
|
email_file.write(content)
|
|
|
|
|
|
@app.post("/send-notification/{email}")
|
|
async def send_notification(email: str, background_tasks: BackgroundTasks):
|
|
background_tasks.add_task(write_notification, email, message="some notification")
|
|
return {"message": "Notification sent in the background"}
|