Helping your asp.net core web API behave!
We all have been around a couple of asp.net web API’s and it’s safe to safe that you can get productive pretty quickly with it, especially if you deploying it to an azure web app or already have an IIS to deploy to!
Sometimes also you inherit an API when you join a new project and the outlook doesn’t look too good. Endpoints that do not perform, different return status code for model validation and even more disparate information for exceptions and so on.
The API is behaving badly! [slap on the hand!!!] I’ll share with you 3 approaches that helped me on the past to improve the API, giving you a quick way to identify slow endpoints, validating models and handling exceptions without need to change the controllers, relying on middlewares and on a global filter to achieve so.
You can find the full source code on this GitHub repo!
behaving not being too slow!
This one is pretty handy if due it’s implementation on a middleware. If you try to put a timer/stopwatch inside your controller and you have one or more filters associated with the method, and your problem is on the filter itself, then you out on the cold.