I have implemented two endpoints:
Post - /users/ #endpoint to add a user
Post - /confirmemail/ #endpoint to confirm email
Now I have function implemented for both endpoints, But I am thinking of calling the email endpoint after adding the user, directly. How can I achieve this in Fastapi?
If one of your functionality will be used by multiple endpoints, you may need to extract it into a separate function (decoupling), for example:
def send_confirm_email():
pass
Then call it in different endpoints:
from .utils import send_confirm_email
@app.post("/users")
def add_user():
# ...
send_confirm_email()
return {"message": "User added, confirm email sent."}
@app.post("/confirmemail")
def confirm_email():
send_confirm_email()
return {"message": "confirm email sent."}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With