things I do

FastAPI Route Middleware

Github Pypi

This is a another python project: it’s a library allows to use middlewares in FastAPI in a manner that, to me, reminds me of how Express.js handles middlewares.

I like Express.js, using it with TypeScript gives me, in my opinion, the right amount of freedom and tools to quickly build web servers that are highly flexible and easy to understand. It lacks in some features, and there are things that are quite hard to do, but in 90% of the cases where I’ve used it, I felt it worked exactly how I want a web server to work.

I currently spend a lot of my coding time using FastAPI. It’s fine, but it’s not Express.js. I want to bring some of what I like of Express.js to FastAPI.

So the first thing I thought of is the amazing modularity of Express.js way of handling middlewares. I don’t know if any other implementation exist, or even if it would be possible to use FastAPI native middlewares in the way I want to use them (I don’t think so honestly).

Next, I want to implement something that allows me to do res.send and res.end in FastAPI without having to end the function that handles a route.

In the meantime, I found out a lot about Python’s own inspect library, and new little tricks that might come in handy in the future.