Matthew Ha
Matthew Ha

Reputation: 143

same with flask.copy_current_request_context in FastAPI?

I'm trying to find fastapi function same with flask copy_current_request_context. (for migrating from flask to fastapi)

Is there any guide for this?

https://flask.palletsprojects.com/en/2.0.x/api/?highlight=copy_current_request_context#flask.copy_current_request_context

Upvotes: 2

Views: 345

Answers (1)

GwynBleidD
GwynBleidD

Reputation: 20539

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).

Upvotes: 1

Related Questions