Skip to content

Category: Web API

Health checks in .netCore web APIs

Previously I have been writing health check controllers by hand. Now .netCore has a simple way of managing service health checks via middleware. You can test everything is operational all the way down to the database. You can even write your own custom checks in a few lines. A simple service operational health check can be enabled by adding two lines to your startup.cs file. One in the services configuration and one in the application configuration. The “/health” parameter specifies the route to be used for the health check. When navigating to the route, a message will be displayed on…

Exception handling in Web API 2

REST Web APIs are becoming more and more popular and have seen a large uptake recently. One of the nicer features that is available in the .NET web API 2 toolkit is it’s inbuilt exception handling. This allows you to maintain separation on concerns and stops controllers becoming bloated beasts of burden, or logging. A common scenario for people who have just started to build Web APIs is to blindly implement try-catch exception handling. This might look something like this As you can see, the actual code that performs the action that we want for this controller method is only…