same with flask.copy_current_request_context in FastAPI?

Viewed 136
1 Answers

There is no such equivalent, because FastAPI doesn't use global variables to keep and communicate to the view the current request context. Instead, all the information you'll ever need will be passed as parameters to your view function.

That means, you don't need the copy_current_request_context in FastAPI. If you're declaring your function inside the view, you don't have to do anything. If the function is declared outside your view, pass everything you'll need as parameters (you may need functools.partial for that).

Related