CodeOath
← All posts
Architecture & Patterns55 min total · 13 parts

Middleware Pipelines Compared: ASP.NET Core, Express.js, and Django

Contents — Part 6 of 13: Side by Side
Part 6 of 13 · ~1 min

Side by Side

ASP.NET CoreExpress.jsDjango
Registrationapp.Use(...) calls, in orderapp.use(...) calls, in orderMIDDLEWARE list, in order
Pass to next layerawait next()next()get_response(request)
Short-circuitDon't call next(); write a response insteadDon't call next(); call res.send() insteadReturn a response without calling get_response
Error handlingtry/catch around await next(), or UseExceptionHandlerFour-parameter (err, req, res, next) middlewareprocess_exception hook, or a try/except around get_response
Per-route middlewareapp.Map(...) branches, or endpoint filtersExtra args in a route definitionDecorators (@login_required) on the view itself
Order sensitivityYes — auth before authorization, alwaysYes — same reasoningYes — listed top to bottom