Creating a Simple RSS Feed with ASP.NET Core Web API

While the terminology might seem alien to us, but at its core its just a web service which returns data from its data source in a predefined XML schema called as RSS. In this article, let's build a simple endpoint in our ASP.NET Core WebAPI which can return RSS feed from a Posts database.

How do you handle errors Globally in ASP.NET Core?

We can make use of the built-in UseExceptionHandler() middleware for catching Global Errors in ASP.NET Core.

app.UseExceptionHandler(err =>
   {
        err.Run(async ctx =>
        {
            context.Response.StatusCode = 500;
            context.Response.ContentType = "application/json";
            // gets error detail
            var ex =  context.Features.Get<IExceptionHandlerPathFeature>();
            var error = new MyResponseModel() { Content = ex.Error.Message };
            await context.Response.WriteAsync(JsonConvert.SerializeObject(error));
        });
    });

How do you design a strongly-typed class for a configuration?

To create a strongly-typed class for binding to a configuration section:

  • The property names and their types match the key names and their value types "exactly" in the configuration.
  • The classes used must be non-abstract with parameterless constructors
  • Only the public accessors (properties) are bound to configuration data but not fields