D Check out @PythonRes, a channel for Python resources - video courses, pdf books, tutorials and other info to help you learn Python.D 3 R A
from fastapi import BackgroundTasks
@app.get("/api/health")
async def health(request: Request, background: BackgroundTasks, visit: bool = False):
...
Today i read newly about this BackgroundTask it looks like it is just a replacement of asyncio.to_thread, as this looks like the backgorund task will be done after the response has send with the return it will run side by side of my main funciton. am i right now?
When using a Flask web app with Flask-Login, a cookie is saved in the browser. If a user attempts to modify the cookie key, Flask detects and blocks the login attempt. What is the best equivalent approach in FastAPI? I have heard that I need to manually implement something with middleware, but I do not understand what is required here. Based on your experience, what do I need to learn to implement a standard email and password login mechanism in FastAPI or any better easy way ?
B R https://fastapi.tiangolo.com/tutorial/middleware/ https://fastapi.tiangolo.com/tutorial/security/first-steps/ And no, in APIs you do not use cookies You use JWT (usually)👍2
G D looks like you need an offtopic group, please delete the off-topic message(s) and continue this conversation at @pythonofftopic
In one of my learning fastapi project i did uv run uvicorn main:app which runs the fastapi server there, what i got a new thigns in the terminal output it shows like this i send below here.
i want to know it shows localhost:random_int what is this why sometime this is same and sometime it is different what is this called is this any important, i rather want to shows timestamp when the req came in log in terminal what do you say will those number 47360,48572... needs when?
INFO: Started server process [9693]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:9999 (Press CTRL+C to quit)
INFO: 127.0.0.1:47360 - "GET /api/health HTTP/1.1" 200 OK
INFO: 127.0.0.1:47374 - "GET /api/health HTTP/1.1" 200 OK
INFO: 127.0.0.1:48572 - "GET /api/health HTTP/1.1" 200 OK
INFO: 127.0.0.1:48572 - "GET /api/health HTTP/1.1" 200 OK
INFO: 127.0.0.1:48572 - "GET /api/health HTTP/1.1" 200 OK
INFO: 127.0.0.1:60242 - "GET /api/health HTTP/1.1" 200 OK
INFO: 127.0.0.1:60250 - "GET /api/health HTTP/1.1" 200 OK
INFO: 127.0.0.1:60242 - "GET /api/health HTTP/1.1" 200 OK
👍1
R As for the *random ports* They are called Ephemeral port https://en.wikipedia.org/wiki/Ephemeral_port As for the logging see https://apitally.io/blog/fastapi-logging-guide👍1😐1