Member-only story
Making Http easier with .NET Core
In this article, I’m going to focus a bit about a few Http related behaviors in .NET that are needed in every microservice or API, but not easily done or found in the wild.
This article is part of a series that tries to look at challenges that faces .NET developers when building microservices.
Everything in this article is packed into one nuget package CoreX.Extensions.Http which you can add to your project and setup in your startup.cs to configure and enable these behaviors.
Better logging for bad requests (400)
Let’s start by the simplest thing, happened a thousand times, someone is calling your API and he send something wrong, missing a field or may be you updated your API and he is not aware that he should have sent a new parameter. He gets an exception but he doesn’t know why, and he asks you for help. The first thing you do is you check the logs of your API, to find this:
With no errors nor warnings, the only indication that something went wrong is the last line saying (as information):
Request finished in … 400 application/json; charset=utf-8With only the 400 status code indicates a non success, without any hint to what went wrong, or what did the caller sent.
Although the caller got a very good Json response:

