ASP.NET Core: Using the ASP.NET Core integration on Azure functions
Introduction
Since 2023, Azure Functions (HttpTriggers) have benefited from an improvement allowing the manipulation of HTTP responses and HTTP requests. So much so that it feels like ASP.NET Core! In this post I will show you how to benefit from these improvements.
What is ASP.NET Core integration?
Microsoft allows, as in ASP.NET Core, to manipulate HTTP requests and responses. Concretely, rather than manipulating objects of type HttpRequestData and HttpResponseData, we can now integrate an ASP.NET Core middleware to manipulate objects of type HttpRequest, HttpResponse and return IActionResult. Wonderful, right?
Let’s do it!
First off, download the following package: Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore
Then go to your Program.cs file and replace the ConfigureFunctionsWorkerDefaults extension by the ConfigureFunctionsWebApplication extension as follows:
Now go on your HttpTrigger and replace HttpRequestData and HttpResponseData by the ASP.NET Core classes.
Before:
After:
Welcome to ASP.NET Core on Azure functions! 🙂