Difference between BackgroundTask, Middlewares and After Request hook #666
-
Hello, everyone. I am a novice web developer and am currently working on a Starlite-based pet project. I don't really understand the difference between BackgroundTask, Middleware, and After Request hook. It feels like these concepts duplicate behavior, but that's probably because I don't understand them very well. Can someone explain the difference to me? Thanks a lot in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @IntrepidCrow. So there is a degree of overlap between these, but there are also key differences. A An As for Middleware - You can do the same as you can with the other two using middleware, but manipulating responses there is low level and more involved. Furthermore, granular control of which handlers are going to be affected by a middleware is also a bit more involved. All in all though, Starlite does not restrict you to use only one pattern - you can choose which one suits your use case best. I would suggest to consider the above in making this determination. |
Beta Was this translation helpful? Give feedback.
Hi @IntrepidCrow.
So there is a degree of overlap between these, but there are also key differences.
A
BackGroundTask
is simply a sync/async callable that is executed once the response is done sending. It has no access to request and and it cannot be defined on different layers of the application.An
AfterRespo…