Skip to content

Difference between BackgroundTask, Middlewares and After Request hook #666

Answered by Goldziher
IntrepidCrow asked this question in Q&A
Discussion options

You must be logged in to vote

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!

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…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by provinzkraut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants